Question

So I am working on a simple app and I ran into a little issue. I had a working app and before I had a table view which was embedded in a navigation controller, and when a cell was selected it would move into the next view where details about the selected row were shown. I decided to make my own custom cell and implemented it into my program, but now when any row is clicked, it does not transition into the other view. Any tips? Are there any methods I have to add into my custom cell class to make it work with my navigation controller again?

Was it helpful?

Solution

Depending on how your app is setup there are a couple of things you could try.

First, if the previous code had tableView:didSelectRowAtIndexPath: implemented, you need to implement similar code to create the details view.

Second, if your app uses storyboard instead, you need to create a push/modal segue from your custom cell to the details view.

Hope that helps.

OTHER TIPS

I too had this issue:

There are 3 ways to go about this with a custom cell class. The first is if you are not using storyboard, you must implement the didSelectRowAtIndexPath as you had before and has been said. I want to elaborate on the other 2 ways.

If you are using a storyboard and you have created your custom class for the cell you can either:

1) Create a .xib file and put your custom cell there.

You must create a Segue by cntrl dragging from your table view (NO prototype cells) to the next view and give it an identifier, in this case "mySegue". Then implement the below method in the table view controller.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"mySegue" sender:self];
}

2) Use a prototype cell. In this case, you add a prototype cell by selecting your table view and incrementing prototype cells to 1, and give it the proper identifier (In the below example it's CellTableIdentifier and then make the prototype cell look as you want with labels and all. Then you make the outlets for the labels to your cell class as you did with your xib file. Now your code is cleaner as you don't need the above method. You just have to make the same call that should be in all the example in the cellForRowAtIndexPath method... mine looks like:

    myTableViewCell *cell = (myTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellTableIdentifier
forIndexPath:indexPath];

Then you just cntrl drag from the prototype cell to the next view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top