在didSelectRowAtIndexPath中的UIButton上的if语句

时间:2010-05-05 13:12:46

标签: iphone objective-c uitableview uibutton

我有一个UITableView,在每个单元格中我有2个自定义按钮,我想要做的是使用didSelectRowAtIndexPath方法我想做一个关于触摸了哪个按钮的if语句

所以我实际上将分裂2个单元格

但我不知道我怎么能怀疑if语句。

任何帮助都会受到欢迎

由于

3 个答案:

答案 0 :(得分:1)

我认为Apple的样本“附件”应用就是您正在尝试做的事情。查看MyTableViewController.m

答案 1 :(得分:1)

使用自定义单元格在自定义单元格中设置按钮   - (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents 设置为适当的方法。

答案 2 :(得分:1)

感谢你帮助的所有人,但我找到了我正在寻找的解决方案。所以这是

你的cellForRowAtIndexPath方法中的

[[cell team1Button] addTarget:self
                       action:@selector(shield1Touched:)
             forControlEvents:UIControlEventTouchUpInside];

    [[cell team2Button] addTarget:self
                           action:@selector(shield2Touched:)
                 forControlEvents:UIControlEventTouchUpInside];

}
[[cell team1Button] setTag:[indexPath row]];
[[cell team2Button] setTag:[indexPath row]];

设置标记,当您在自定义单元格中选择按钮时,应用程序会知道选择了哪一行。

然后按下按钮按下方法

- (IBAction)shield1Touched:(id)sender;{
WorldCupAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;

    int rowOfButton = [sender tag];
ScoreDetails *scoreDetail = [appDelegate.liveMatch objectAtIndex:rowOfButton];

那么你可以执行你需要的所有动作,具体取决于触摸哪个按钮

希望这有助于其他人

信息来源是here