views:

890

answers:

1

Here is the situation,

I have UIViewController class with a UITableView outlet. I would like to modify / style the cell. I believe I can do this with UITableViewCells tableviewCellWithReuseIdentifier method. Since my class is not a UITableViewController it doesn't have this method. How can I use this method from the UIViewController class.

Also I know I can create a custom UITableViewCell class and instantiate it instead of a regular UITableViewCell class but is there anyway that I can do this in the UIViewController class?

Thanks, Joe

A: 

A UITableViewController is essentially a UIViewController with a UITableView instance and the viewController itself set as the delegate and dataSource for the table (which implies that the viewController implements stubs for those delegate methods).

You can do it yourself by having your UIViewController implement the UITableViewDataSource and UITableViewDelegate protocols. Then in the UIViewController's loadView (or viewDidLoad) method set the tableView instance's dataSource and delegate to self.

To return a custom cell, in your UIViewController implement the cellForRowAtIndexPath method and return the custom cell.

Also, check out Matt Gallagher's post on ways to customize a table cell without having to subclass UITableViewCell: http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

Ramin
well done explanation, thanks a million!
Buffernet