Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mmalsn

macrumors newbie
Original poster
Jul 20, 2011
13
0
hi guys

I have Tableview an of course it has cells

and I add 3 buttons for each cell and one event for all cell


the problem is i want to know which button is being selected to open a screen according to this value

Thanks.
 
Give the buttons a tag each and check the returned tag from inside the assigned action

- Olaf
 
hi guys

I have Tableview an of course it has cells

and I add 3 buttons for each cell and one event for all cell


the problem is i want to know which button is being selected to open a screen according to this value

Thanks.

A couple of questions pop into my head immediately:
  • How many rows?
If it's a bunch of rows (that is, > 1 screen full of rows), then the rows will exit the screen and be put back into the reuse pool (if you're taking advantage of that). That means that the row will not have a fixed mapping to buttons. Think about how you can solve the mapping between a button press and which row & button was pressed.
  • How do the buttons get into the cells?
This is a dual to the above problem - once you pull a cell from the reuse pool, how can you ensure the correct button is put into that cell? Do they come with because you're instantiating a UITableViewCell subclass from a nib?
If I were doing this, I'd have to fiddle with the data structures for a little bit. I'd probably start with a couple of (lazy instantiated) mappings between buttons, indexPaths, and actions (push a view controller being one of those actions). Something like a buttonToIndexPath and indexPathToButton dictionary for the cross relationship and buttonToAction dictionary.

When constructing a cell, I'd put the appropriate button objects for the requested indexPath into the cell's contentView, getting the objects from the dictionary mentioned above.

Each of the button's action points to the same method (-(IBAction)buttonPress: (id)theButton) where I'd use theButton to figure out WHICH button was pressed by interrogating the dictionaries I created earlier. I could also see 3 different action methods (button1pressed, button2pressed, button3pressed) with code specific to each kind of button (so I wouldn't have to make the mapping between button and action), but the code would still likely have to know the indexPath associated with the button.

I tend to go to over-sophisticated on data structures, so I'm likely missing a simpler version of this.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.