1

I am new in iPhone development and now I have simple question(may be not simple:). I have a UITableView, and in that UITableView I have for example 5 rows, every row has a UILabel and UIButton.

What I want to do is to delete one element from the array when my button is pressed. Button I create with tag, but that doesn't work. I do not want use didSelectRow; I want to delete an element from the array only if my button was pressed. (For example, if the third button was pressed I want to delete the third element of the array. Using the standard delete button does not work for me.

yuji
  • 16,695
  • 4
  • 63
  • 64
user941313
  • 13
  • 3

1 Answers1

2

If you have a custom UIViewController to manage each cell (which I highly recommend), simply wire up the button to an IBAction and have that method remove the item from whatever data structure supplies the UITableView with rows, and then tell the UITableView about it.

Failing that, I suppose you could attach a tag to each button, indicating which row it belongs to, and wire them all up to a single IBAction in your table-view controller.

Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365
  • That is, the idea of ​​playing with the `[button tag]` is not a good idea? – user941313 Sep 13 '11 at 05:20
  • It's perfectly find, and it spares you from creating a custom view controller for each cell. But I find that I almost always end up wanting a customer controller anyway. – Marcelo Cantos Sep 13 '11 at 11:12