2013-08-26 4 views
-3

У меня есть адресная книга в моем приложении. В этом случае есть таблица и страница контактной информации (см. Скриншот). Когда я добавляю новый контакт, последние данные о контакте отображаются на странице сведений о контакте, но как сделать недавно добавленный контакт выбранным в 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]; 
    } 

ИЛИ

Если вы добавляете где-либо в Tableview затем получить индекс вашей массив, тогда получите indexPath, затем примените Code, например.

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

Где следует использовать этот код? – user2640613

+0

cellForRowAtIndexPath – Rajneesh071

Смежные вопросы