Select uitableview row programmatically

后端 未结 2 538
既然无缘
既然无缘 2021-02-08 01:48

i have read a lot on this argument, i have tested this example that works: source code example. but this doesn\'t use storyboards (i don\'t know if this is the reason that make

相关标签:
2条回答
  • 2021-02-08 01:57
    - (void)viewDidLoad {
        [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
    }
    

    If you want the callback from the delegate:

    if ([self.tableView.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
        [self.tableView.delegate tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    }
    
    0 讨论(0)
  • 2021-02-08 02:01

    I tried to study your code downloading the project.The problem is that firstController.tableView is nil.
    So fix it:

    [firstTable selectRowAtIndexPath:indexPath 
                            animated:NO 
                      scrollPosition:UITableViewScrollPositionNone];
    

    Or assign firstController.tableView to the table view.

    0 讨论(0)
提交回复
热议问题