English 中文(简体)
为什么UIButton的行动在UIBCroll 意见内就没有被叫去。
原标题:Why are UIButton actions not being called when UIButton is inside a UIScrollView

我创建了一个像小组这样的跳板,其中包括:

-(void)configurePanel{

self.criteriaPanel.scrollEnabled=YES;
self.criteriaPanel=[[UIScrollView alloc] initWithFrame:CGRectMake(
                                                                0.0f, 
                                                                0.0f, 
                                                                [UIScreen mainScreen].bounds.size.width,
                                                                (BUTTON_HEIGHT+(3*BUTTON_Y_OFFSET))
                                                                )];

UIView *scrollViewContent=[[UIView alloc]init];
NSArray *criteriaTypeButtonTitles=[NSArray arrayWithObjects:
                                 @"Option1",
                                 @"Option2",
                                 @"Option3",
                                 @"Option4",
                                 @"Option5",
                                 @"Option6",
                                 nil
                                 ];

for (int i=0; i<[criteriaTypeButtonTitles count]; i++) {
  UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  button.tag=i;
  button.frame = CGRectMake(
                          (((BUTTON_X_OFFSET*i)+(BUTTON_WIDTH*i))+BUTTON_X_OFFSET)
                          , BUTTON_Y_OFFSET
                          , BUTTON_WIDTH
                          , BUTTON_HEIGHT
                          );  
  [button setTitle:[criteriaTypeButtonTitles objectAtIndex:i] forState:UIControlStateNormal];
  [button setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
  button.titleLabel.font=[UIFont systemFontOfSize:13.0f];
  [button setBackgroundColor:[UIColor grayColor]];
  [button.layer setCornerRadius:10.0f];
  [button.layer setBorderWidth:1.0f];
  [button addTarget:self action:@selector(sortByButtonTap:) forControlEvents:UIControlEventTouchDown];
  [scrollViewContent addSubview:button];
}

//based upon # of buttons
self.criteriaPanel.contentSize=CGSizeMake(
                                        (([criteriaTypeButtonTitles count]*BUTTON_WIDTH)+([criteriaTypeButtonTitles count]*BUTTON_X_OFFSET)),
                                        (BUTTON_HEIGHT+(2*BUTTON_Y_OFFSET)));
[self.criteriaPanel addSubview:scrollViewContent];
[self.view addSubview:self.criteriaPanel];
}

小组显示的是正确的,是滚动的,但 never子的主食(ByButtonTap:)从未被叫到。 我怀疑这一点与《发展概览》所载观点中所载的纽州有关。 在阅读了其他一些问题和一些特约之后,我仍然可以说明解决办法是什么。

EDIT: I experimented w/ adding the buttons to the UIScrollView (self.criteriaPanel) directly and the button taps call sortByButtonTap: so it is something to do w/ the buttons being in the scrollViewContent.

问题回答

您也许需要为纽芬兰州制定<代码>用户可交易<>编码>,以备接收触动活动:

[scrollViewContent setUserInteractionEnabled:YES];

如果你试图:

[button setExclusiveTouch:YES];

但是,当他们处于同样处理触动事件的观念之中时,他们往往会不正常地工作。

3. 遵循您的询问守则,

Add UIButton in Scrollview

    scrollview.pagingEnabled = YES;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake();
    [button setTitle:@"X" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(btnCloseClicked:withEvent:) forControlEvents:UIControlEventTouchUpInside];
    [button addTarget:self action:@selector(btnCloseDraged:withEvent:) forControlEvents:UIControlEventTouchDragInside];
    [button addTarget:self action:@selector(btnCloseDragedEnd:withEvent:) forControlEvents:UIControlEventTouchDragExit];
    [scrollview addSubview:button];
    scrollview.userInteractionEnabled = YES;

you can put this three methods of button manually.

让我知道你是否仍然有疑问。

而不是:

[button addTarget:self 
           action:@selector(sortByButtonTap:) 
 forControlEvents:UIControlEventTouchDown];

审判:

[button addTarget:self 
           action:@selector(sortByButtonTap:) 
 forControlEvents:UIControlEventTouchUpInside];

我认为,你的问题只是把错误的<条码>查询/编码>贴在<条码>上。 从<条码>ControlEventTouchDown/code>改为<条码>。 如果您在<代码>内连接。 界面构建器将始终将其置于之上。 UIControlEvent:

“entergraph

另一个原因是:

页: 1 观点控制了互动关系,因为它需要知道你是否希望进行交流。 如果您在<条码>内登上。 意见可以查阅,但总是稍有延误。 因此,你可能会改变<代码>的环境。 缩略语 观点:

可在<条码>中查询和<条码>查询。

“entergraph





相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签