0

加载视图时,tableview 将选择第一行并触发 didselectatrow 方法来执行某些操作。我只知道如何选择第一行,但它不会同时触发 didselectatrow 方法 告诉我如何这样做

4

1 回答 1

5

您可以手动调用该方法viewDidLoad

- (void)viewDidLoad {
    [super viewDidLoad];

    // select the first row
    NSIndexPath *firstRowPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableView selectRowAtIndexPath:firstRowPath animated:NO scrollPosition: UITableViewScrollPositionNone];
    [self tableView:self.tableView didSelectRowAtIndexPath:firstRowPath];
}
于 2013-05-10T02:57:09.680 回答