imbeginner_sorry imbeginner_sorry - 1 month ago 9
Objective-C Question

Viewcontroller appear twice when I click cell

I have a problem.

I have a ViewController embed in navigationController.

And use the storyBoard to add the tableView in this viewController.

then,I add the segue.

Finally,I click the cell that the next viewController show twice.

I don't know how to fix it.

Thanks!


This is my code:


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

if(indexPath.row == 2){

[self performSegueWithIdentifier:@"showAdd" sender:self];

}

}

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

if ([segue.identifier isEqualToString:@"showAdd"]) {

AddCommentViewController *AddCommentVC = segue.destinationViewController;

AddCommentVC.CommentString = _DetailString;

}

}

Answer

You have to add the segue between both the UIViewController, not with the cell and UIViewController, as you have connected that segue on click of cell and you are calling the segue manually also that's why it is showing twice.

Do one thing, remove the segue and connect it between UIViewControllers then it will called only once.