imbeginner_sorry imbeginner_sorry - 9 months ago 51
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.


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 Source

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.