Automatically cell selected UITableView

前端 未结 1 670
情歌与酒
情歌与酒 2020-12-18 13:01

My UITableView opens via PopOverViewController , so How can I load one of these cells automatically after app did load ,

the cell selecting process on MainViewContr

相关标签:
1条回答
  • 2020-12-18 13:49

    When you call selectRowAtIndexPath:animated:scrollPosition:, tableView:didSelectRowAtIndexPath: is not called on the delegate.

    From the selectRowAtIndexPath:animated:scrollPosition: reference:

    Calling this method does not cause the delegate to receive a tableView:willSelectRowAtIndexPath: or tableView:didSelectRowAtIndexPath: message, nor will it send UITableViewSelectionDidChangeNotification notifications to observers.

    So, instead of just calling selectRowAtIndexPath:animated:scrollPosition::

     [myTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];
    

    you could call the delegate methods manually:

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    
    if ([myTableView.delegate respondsToSelector:@selector(tableView:willSelectRowAtIndexPath:)]) {
        [myTableView.delegate tableView:self.tableView willSelectRowAtIndexPath:indexPath];
    }
    
    [myTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition: UITableViewScrollPositionNone];    
    
    if ([myTableView.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
        [myTableView.delegate tableView:self.tableView didSelectRowAtIndexPath:indexPath];
    }
    
    0 讨论(0)
提交回复
热议问题