0

In my project I've got UITableView. I need to assign different buttons, with different behaviours for different columns.

Question:

  1. Where is the correct way to set different behaviours & actions for buttons? Is it in (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath?
  2. How is the correct way to assign different buttons with different behaviours to different columns? I am thinking about [_buttonArray objectAtIndex:indexPath.section]; is it the right way?

Example: Column 1 - Button A -> after button A pressed change button.title and size and do X.

Edgar
  • 898
  • 2
  • 12
  • 36

1 Answers1

1

You should use the below method for button behaviors if you want the user to be able to hit the entire cell and have the button action fire. If not, you should use an action delegate in your custom cell class. Let me know if you need help setting up the protocols file and or delegate method.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}
  • but if I also want to select a cell when a button in a cell header/footer pressed? where then? – Edgar Mar 25 '15 at 21:37
  • so I need to make that button a delegate and in my button class make all the coding for the button? like if button is pressed // if it is pressed 1 time etc. – Edgar Mar 25 '15 at 21:38
  • Imagine: I have a lot of cells and 2-4 button types. One button of one type in each cell. Then when the user presses a button "FREE" something happens, or if he presses a button "0.99$" (in another cell) he triggers in-app purchase method.. – Edgar Mar 25 '15 at 21:44
  • 1
    I'm not sure how would fire an action if the cell header/footer is pressed. If you have a button in a custom cell then you want to set up a delegate method. When the user hits the button in the cell, the button's target method will be fired in the cell class which will fire a delegate method and that will perform x in the place where you init the table view (view controller,view, etc). How to set up a delegate method in a custom cell class, http://stackoverflow.com/questions/8062572/adding-a-delegate-to-a-custom-uitableviewcell-bad-access-error If that isn't enough, I'll walk you through it. – Lee J Pollard Mar 25 '15 at 21:49
  • 1
    Yes, you set up a delegate methods for each button class. So, a delegate method for the "FREE" button, and another delegate method for the "0.99" button. – Lee J Pollard Mar 25 '15 at 21:51
  • 1
    If that link I shared isn't good enough to show you how to set up delegate methods for buttons, please let me know and I'll walk you through how to them up using a project I recently completed. – Lee J Pollard Mar 25 '15 at 21:56
  • Thank you! I've tried to use [this](https://github.com/MoathOthman/MoStoreButton) button, but just dont know how to set up it correctly - I dont have a downloadable content, so I dont need that download progress circle, just cant remove that circle (I need to pass to next button state omitting progress circle) May be you have used that button? – Edgar Mar 25 '15 at 22:52