views:

90

answers:

3

hi guys,

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 i have no idea how i could wright the if statements.

any help would be greatly welcomed

Thanks

+1  A: 

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

Rob
hmm , not really , because that is the accesory image,what im looking for is something likeif(UIButton1 received touches){if(UIButton2 received touches){if that helps any
richard Stephenson
But if you are looking for confirmation of a touch in the UIButton, just set up an action as described above. What am I missing here?
Kenny
+1  A: 

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.

Kenny
A: 

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

richard Stephenson