aVC
aVC

Reputation: 2344

Adding a custom cell at the end of tableview

I have a situation where I need to display more than one sections in a grouped table. Each section has three content rows and I need a "View More" row. The content row will open a detail view, where as "view more" will open a tableview with status messages. Need some help with

  1. The prototype cell is set to have the image and the labels. So I am not sure how to add the "View More" Row in the end.

  2. Am I right in using dynamic prototypes ( I have it working pretty much) or is static cells the right choice?

enter image description here

Upvotes: 2

Views: 1824

Answers (2)

lakshmen
lakshmen

Reputation: 29104

Create an array to contain all the status messages. Group them according to the section when you initialise the screen. You could give the same index to the groups as the section as well. In the didSelectRowAtIndexPath method, when a particular section is clicked, pass the particular section of the status messages to the next view controller.

Hope you get my idea and this helps you..

Adding the custom cell to the end of each section can be done as @dasklinkenlight said...

Upvotes: 1

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 727137

The prototype cell is set to have the image and the labels. So I am not sure how to add the "View More" Row in the end.

You are not limited to a single prototype cell per table. Add a custom cell for the "View More" cell, then add some code to your tableView:cellForRowAtIndexPath: method to pick the "main" prototype for the top cells, and the "view more" prototype for the last cell.

-(UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
    UITableViewCell *cell;
    if (indexPath.row != [self numberOfRowsInSection:indexPath.section]-1) {
        cell = [tableView dequeueReusableCellWithIdentifier:@"mainPrototype"];
        ...
    } else {
        cell = [tableView dequeueReusableCellWithIdentifier:@"viewMorePrototype"];
        ...
    }
    return cell;
}

Am I right in using dynamic prototypes ( I have it working pretty much) or is static cells the right choice?

Yes, this is the right choice.

Upvotes: 5

Related Questions