Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 目标c中的多按钮操作问题_Iphone_Objective C - Fatal编程技术网

Iphone 目标c中的多按钮操作问题

Iphone 目标c中的多按钮操作问题,iphone,objective-c,Iphone,Objective C,我在objective c中使用带有不同标记的for循环创建了按钮,但问题是除了前2-3次单击按钮外,它不调用BtnClick函数。任何帮助都将不胜感激 for(int i = 0; i<40; i++) { UIButton butContinue... btnContinue.tag=i; [btnContinue setTitle:[NSString stringWithFormat:@"%d",i] forState

我在objective c中使用带有不同标记的for循环创建了按钮,但问题是除了前2-3次单击按钮外,它不调用BtnClick函数。任何帮助都将不胜感激

for(int i = 0; i<40; i++) 
{ 
   UIButton butContinue...  
   btnContinue.tag=i; 
    [btnContinue setTitle:[NSString stringWithFormat:@"%d",i] 
                 forState:UIControlStateNormal];   
    btnContinue.autoresizingMask=YES; 
    [btnContinue addTarget:self 
                    action:@selector(clickBtn_Continue:)     
         forControlEvents:UIControlEventTouchUpInside]; 
}
循环代码以创建按钮

行动像


请同时动态设置框架。在这段代码中,它将在同一帧上添加40个按钮。初始化 带有alloc init的按钮。所以它不会自动释放。下面使用
UIButton*yourButton=[[UIButton alloc]initWithFrame:CGRectMake0,0,50,50];//并动态设置框架

是否检查了按钮框架的大小?如果它很小,你的第一次接触可能是外侧按钮!!!我想是的。我的代码是:forint I=0;我在按钮中添加了图像,这样我可以在这里单击特定的按钮。但是现在在这里调用了操作。@VishwanathDeshmukh,如果代码相同,那么它应该可以正常工作!
 UIButton *yourButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 [yourButton setFrame:CGRectMake(x, y, 50, 50)];
 [yourButton setTitle:@"Click Here" forState:UIControlStateNormal];
 [yourButton addTarget:self action:@selector(yourAction:) forControlEvents:UIControlEventTouchUpInside];
 yourButton.tag = tag;
 [self.view addSubview:yourButton];
 //increment x or y as per your need,
- (IBAction) yourAction : (UIButton *) sender
{
      NSLog(@"I'm %d pressed.",sender.tag);
}