【问题标题】:How show selected row when click on table view?单击表格视图时如何显示选定的行?
【发布时间】:2011-09-02 12:01:11
【问题描述】:

我有一个按钮。单击按钮时,打开一个包含 100 行的表格视图。我用户选择任何一行然后出现复选标记。当用户再次单击时,我想在视图打开时显示选定的行。怎么做?例如,当用户单击按钮然后打开表格视图并假设选择第 50 行。现在用户再次单击按钮然后我想直接显示第 50 行而不是用户转到滚动表视图。那告诉我怎么做? 提前谢谢..

【问题讨论】:

    标签: iphone uitableview row nsindexpath


    【解决方案1】:

    只要打电话

    - (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition
    

    到您的表格视图。

    例如,以下代码将选择第一部分的第 50 行:

    UITableView *tableView;
    [tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:50 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionTop];
    

    【讨论】:

    • 我使用但我不工作。我有 uiview,其中有一个表格视图。我如何使用它?
    • 你有参考你的tableView吗?
    • 是的,我得到了表格视图的参考。
    • 然后拨打[yourReferenceToTableView selectRowAtIndexPath:...]
    【解决方案2】:

    使用,

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:selectedRow
                                                inSection:sectionOfSelectedRow];
    [tableView scrollToRowAtIndexPath:indexPath animated:YES];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多