How to programmatically “tap” a UITableView cell?

后端 未结 5 1042
梦如初夏
梦如初夏 2020-12-25 15:23

I was wondering is there a way that I could have my code \"tap\" a cell in my UITableView in order to reproduce the behaviour specified in the - (void)tableView:(UITab

5条回答
  •  醉梦人生
    2020-12-25 16:01

    This is a 6.1 update. When you are using segues- all the advice is good, but you also have to invoke the segue. So - to add to the advice and summarize it

    // ... assuming we just added a new row - which is one use of what this thread is trying to do
    
    /* get new count - this is the row we are going to highlight - 0 based */
     int newIndex = [dataArrayUnderlyingTable count]-1; 
    
    /* make it look pretty by highlighting it */
        NSIndexPath *nip = [NSIndexPath indexPathForRow:newIndex inSection:0];
        [[self tableView] selectRowAtIndexPath:nip animated:YES scrollPosition:UITableViewScrollPositionBottom];
    
    /* run the code in the following method so it is not missed */
        [self tableView:[self tableView] didSelectRowAtIndexPath:nip];
    
    /* now 'tap' on it ... or simulate it */
        [self performSegueWithIdentifier: @"viewChildDetails" sender: self];
    

提交回复
热议问题