Kru*_*nal 3 iphone uibutton sender ipad ios
我是一名新的iPad开发人员.
我已经以编程方式创建了UIButton,我希望识别用户已经点击了哪个按钮,并根据我想要做一些动作.
我应该如何识别这个?
这是我的代码片段:
for(int i=0;i<[_array count];i++)
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.tag=count;
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
button.backgroundColor=[UIColor redColor];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(xpos, 270.0, 200.0, 150.0);
[self.view addSubview:button];
}
Run Code Online (Sandbox Code Playgroud)
这就是我现在正在做的事情:我想我会为每个按钮分配计数,然后我会将此计数传递给按钮点击方法.这是一个好主意吗?还有其他方法吗?
在按钮上单击我正在呼叫aMethod:
-(void)aMethod:(id)sender{
NSLog(@"btn clicked");
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激!
ada*_*ali 16
-(void)aMethod:(UIButton*)sender{
NSLog(@"btn clicked %d", sender.tag);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2713 次 |
| 最近记录: |