Using a UITableView subclass with a UITableViewController
Asked Answered
E

3

16

How can I tell my UITableViewController to use my custom UITableView subclass for it's tableView instead of a regular UITableView?

Extrauterine answered 17/5, 2009 at 16:17 Comment(0)
C
18

Set the UITableViewController.tableView property to an instance of your custom UITableView subclass.

Continuative answered 17/5, 2009 at 16:56 Comment(3)
let's say I do this in initWithStyle: after I set self = [super initWithStyle:style]. How do I know what changes -[UITableViewController initWithStyle:] made to its tableView? I might be undoing those. See #8513293Nautilus
Imho, the nicest place for this is to override loadView with something like self.tableView = [[MyTableViewSubclass alloc] init] or something of the sort.Divisor
If you do that, make sure to set the delegate and dataSource too or your table won't load anything.Plowman
S
7

In interface builder associate the tableview class with your custom tableview in the identity inspector view

Squall answered 17/5, 2009 at 16:57 Comment(0)
E
-3

A UITableViewController is just a UIViewController with a UITableView instance and the viewController set as the delegate and dataSource for the table. The viewController implements stubs for those delegate methods.

You can do it yourself by having a 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.

You can use your own table subclass there.

Empoverish answered 17/5, 2009 at 20:45 Comment(4)
This is misleading. UITableViewController also includes keyboard avoidance, for example.Cookhouse
what is keyboard avoidance ?Azzieb
when you have a text field inside a cell the table is resized when the keyboard comes up and the text field is kept in view.Cermet
Not true, uitableviewcontroller doesnt have a view property. There are more differencesFelipafelipe

© 2022 - 2024 — McMap. All rights reserved.