【发布时间】:2013-12-14 13:24:39
【问题描述】:
我正在处理 iphone 项目。在那我添加了 3 个具有相同选择器名称的按钮(即动作)。现在我正在使用查询从数据库中获取数据。但只有当我按下三个按钮中的任何一个时,它才会向我显示第三个按钮的数据。
btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(80, 30, 200, 50);
[btn.layer setBorderWidth:0];
btn.tag = 1;
[btn setTitle:@"1" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(detail:) forControlEvents:UIControlEventTouchUpInside];
btn.titleLabel.font = [UIFont fontWithName:@"Zapfino" size:14.0];
[scrollview addSubview:btn];
btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(80, 30, 200, 50);
[btn.layer setBorderWidth:0];
btn.tag = 2;
[btn setTitle:@"2" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(detail:) forControlEvents:UIControlEventTouchUpInside];
btn.titleLabel.font = [UIFont fontWithName:@"Zapfino" size:14.0];
[scrollview addSubview:btn];
btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(80, 30, 200, 50);
[btn.layer setBorderWidth:0];
btn.tag = 3;
[btn setTitle:@"3" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(detail:) forControlEvents:UIControlEventTouchUpInside];
btn.titleLabel.font = [UIFont fontWithName:@"Zapfino" size:14.0];
[scrollview addSubview:btn];
这是我正在使用的操作。
-(IBAction)detail:(id)sender
{
detailViewController *detailvc =[[detailViewController alloc]initWithNibName:@"detailViewController" bundle:Nil];
detailvc.btntxt = btn.tag;
NSLog(@"name of btn :%ld",(long)btn.tag);
[self.navigationController pushViewController:detailvc animated:YES];
}
在 nslog 中,我也只获得了第三个按钮的选项卡 请帮我解决这个问题...
【问题讨论】:
-
你不应该对所有 3 个按钮使用相同的标签
-
抱歉,我错误地使用了不同的标签值.....
-
所有这些按钮都在同一个位置吗? CGRectMake(80, 30, 200, 50)?请粘贴您的原始代码,以便每个人都可以看到问题所在