PrepareForSeque not working

I have a UIViewController with a button, the button opens firstTableViewController → tabViewController (with 3 tabs) → on one of the tabs there is a secondTableViewController → UIViewController.

Everything is in the storyboard.

In the firstTableViewController, the prepareForSeque command works fine. I don't even have didSelectRow ...

But on secondTableViewController, the ready ForSeque does not work. So I added didSelectRowAtIndexPath as follows. But still workForSegue does not work.

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

-(void) performSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
    [self prepareForSegue:self.storyboard sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {


    //When a row is selected, the segue creates the detail view controller as the destination.      
    //Set the detail view controller detail item to the item associated with the selected row.
NSLog(@"test");
    if ([[segue identifier] isEqualToString:@"ShowComment"]) {

    }
}
0
source share
1 answer

I found a problem. I did not have an identifier for the cell. We selected the prototype cells in the storyboard, in the identifier of the attribute inspector → the identifier entered in "Cell1".

In code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell1";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    Note *note = [notes objectAtIndex:indexPath.row];
    cell.textLabel.text = note.title;
    return cell;
}

voila, he worked.

0

All Articles