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

iphonejudy

macrumors 6502
Original poster
Sep 12, 2008
301
1
Hi,

I want to add button in tableview.

In the design time i cannot add button in tableview.Can i add it in the coding?

If so, how?
 

johnnyjibbs

macrumors 68030
Sep 18, 2003
2,964
122
London, UK
Coding is your friend - Interface Builder will be of no use here.

Probably best to subclass UITableViewCell and add a button as a subview during cell initialisation, but you don't have to subclass.

If you don't want to subclass, you can initialise the button somewhere within the cellForRowAtIndexPath method (I normally create the tableView:dequeueCellWithIdentifier: and configureCell:atIndexPath: methods as in some of the Apple examples). The key thing is to add the button as a subview of the cell's content view in a similar way to how you would add a custom label:

Code:
[cell.contentView addSubview:myButton]

There are several good examples that illustrate this (e.g. UITableView examples 1-5 or perhaps CustomCell).

Don't forget to release your button instance once you have added it as a subview as the parent view (in this case the cell's content view) retains its subviews at the point you add them.

Hope that gives you a starting point.
 

iphonejudy

macrumors 6502
Original poster
Sep 12, 2008
301
1
Actualy i placed the tableview control in my view , and i want to add the button in the last cell of tableview

How can i addit?
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
Do you need a button in a cell or a button as a cell? If the second then you could create a button and set it as the tableview's footer view. You will have to do this in code as I don't think you can do it in IB.
 

iphonejudy

macrumors 6502
Original poster
Sep 12, 2008
301
1
Do you need a button in a cell or a button as a cell? If the second then you could create a button and set it as the tableview's footer view. You will have to do this in code as I don't think you can do it in IB.


i want to add button in the 6th cell of the tableview
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.