2013-08-26 39 views
-3

我的應用程序中有一個地址簿。在那裏,有一個tableview和一個聯繫細節頁面(請參閱截圖)。當我添加一個新的聯繫人時,最近添加的聯繫人詳細信息會顯示在聯繫人詳細信息頁面中,但是如何在tableview中選擇最近添加的聯繫人。注意:聯繫人在表格視圖中按字母順序排序..在UITableview中選擇一個特定的行

回答

0

在要選擇的單元上使用setSelected:(BOOL)selected方法。

0
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. 
0
[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]; 
1

如果要添加你最近的陣列中的tableView的末尾,則

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

OR

如果你在的tableView添加任何地方,然後得到的索引你的數組然後獲得indexPath然後applyCode,就像。

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

在哪裏可以使用此代碼? – user2640613

+0

cellForRowAtIndexPath – Rajneesh071

相關問題