我有一个基于视图的应用程序,我正在添加一个表视图作为主视图的子视图。我使用了UITableViewDelegate来响应表格方法。一切正常,但我想选择第一行或UITableView作为默认选择(突出显示)。
请帮助我,我需要什么代码,我需要把它放在哪里。
发布于 2011-05-31 15:22:29
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:0];
    [myTableView selectRowAtIndexPath:indexPath animated:YES  scrollPosition:UITableViewScrollPositionBottom];
}在您的代码中使用它的最好方法是,如果您想默认选择任何行,请使用in viewDidAppear。
发布于 2016-11-14 20:38:46
Swit 3.0更新的解决方案
let indexPath = IndexPath(row: 0, section: 0)
tblView.selectRow(at: indexPath, animated: true, scrollPosition: .bottom)发布于 2012-01-05 21:58:33
- (void)viewWillAppear:(BOOL)animated
    {
       [super viewWillAppear:animated];
     // assuming you had the table view wired to IBOutlet myTableView
        // and that you wanted to select the first item in the first section
        [myTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];
    }https://stackoverflow.com/questions/2728152
复制相似问题