【问题标题】:Selecting a specific row in UITableview在 UITableview 中选择特定行
【发布时间】:2013-08-26 17:58:19
【问题描述】:

我的应用中有一个通讯录。在那,有一个表格视图和一个联系方式页面(参考截图)。添加新联系人时,最近添加的联系人详细信息显示在联系人详细信息页面中,但是如何在表格视图中选择最近添加的联系人..?注意:联系人在表格视图中按字母顺序排序..

【问题讨论】:

    标签: iphone ios uitableview selection


    【解决方案1】:

    如果您在 tableView 的末尾添加最近的数组,那么

    if (indexPath.row==[yourContactAry count]-1) {
            [tableView selectRowAtIndexPath:indexPath
                                        animated:NO
                                  scrollPosition:UITableViewScrollPositionNone];
        }
    

    如果您在 tableView 中添加任何位置,则获取数组的索引,然后获取 indexPath,然后应用代码,例如。

    NSInteger indexOfArry=[yourContactAry indexOfObjectIdenticalTo:yourRecentAddedRecord];
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:indexOfArry inSection:section];
    

    【讨论】:

    • cellForRowAtIndexPath
    【解决方案2】:
    if you are maintaining contacts array then take the topmost item as the reference of your last created contact.
    Or else if you are having any index of the contact then take that index and point to the array your contact is stored.
    or else if your contact object or address object has the date field compare that with other records and fetch the latest one.
    

    【讨论】:

      【解决方案3】:
      [self.tableView selectRowAtIndexPath:selectedIndexPath
                                                            animated:NO
                                                    scrollPosition:UITableViewScrollPositionNone];
      
      
      set selectedIndexPath in which you want, if select top most item means,
      
      _selectedIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
      

      【讨论】:

        【解决方案4】:

        在要选择的单元格上使用setSelected:(BOOL)selected 方法。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-11-13
          相关资源
          最近更新 更多