设置UITableView中Cell被默认选中后怎么触发didselect事件

2025-05-10 08:34:48
推荐回答(1个)
回答(1):

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];

}