I am addicted to use TableViewController in storyboard whose class directly inherits from UITableViewController and functions like:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
are there by default and you just have to implement them. But now I am using a ViewController (inherits from UIViewController) in storyboard and using a UITableView control from Object library into the view controller by drag and drop. Obviously the class I would attach to my storyboard ViewController will be inherited from UIViewController. Now how do I interact with the table cells in the UITableView control in my view controller. Want to implement same row functions above.
There are two main base ways to populate a tableview. The more popular is through Interface Building, using a prototype cell UI object. The other is strictly through code when you don't need a prototype cell from Interface Builder.
The appearance of the tableview is managed by UITableView class, which inherits UIScrollView. In tableview, the row is simulated by the object of the UITableViewCell class, which can be used to display the actual content.
IndexPath contains information about which row in which section the function is asking about. Base on this numbers you are configuring the cell to display the data for given row.
Tableiw is a simple list, which displays single-dimensional rows of data. It's smooth because of cell reuse and other magic. 2. UICollectionView is the model for displaying multidimensional data .
Implement UITableViewDataSource
and UITableViewDelegate
protocols in your view controller .h file.
Have an outlet for the UITableView
.
In viewDidLoad
, set the tableView's datasource and delegate to self
since the viewcontroller implements the protocol.
Then, write the cellForRowAtIndexPath
method. It will be getting called.
You have to assign UITableViewDelegate and UITableViewDatasource protocols to your table and implement it. Methods in your question are methods from these protocols and they appears automatically when you use UITableViewController.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With