开发者

if statement on UIButton within didSelectRowAtIndexPath

i have a UITableView , within each cell i have 2 custom buttons, what i want to do is withing the didSelectRowAtIndexPath method i want to do an if statement on which button was touched

so i would effectively be splitting a cell in 2

but开发者_StackOverflow中文版 i have no idea how i could wright the if statements.

any help would be greatly welcomed

Thanks


I think Apple's sample "Accessory" app does just what you are trying to do. Check out the MyTableViewController.m


Set up the buttons in a custom cell with their - (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents set to the appropriate method.


Thanks for all you help guys, but i found the soloution i was looking for. so here it is

in your cellForRowAtIndexPath method

[[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]];

set the tag so , when you select the button within your custom cell, the app knows which row was selected.

so then on your button pressed method

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

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

so then you can perform all the actions you need depending on which button was touched on which cell

hope this helps someone else

source for information was here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜