tableView scrollToRowAtIndexPath: atScrollPosition: animated: with a text to find in textLabel.text
I have a tableView connected to coreData. Is it possible to use the method tableView scrollToRowAtIndexPath: atScrollPosition: animated: so that the tableView scrolls to the correspondent row that has a specific string in tex开发者_StackOverflow中文版tLabel.text?
In alternative, i can store, the indexPath. But without that?
Thanks,
RL
Yes this is very achievable, and can be done with a simple for() loop logic search:
- (int) indexForSearchTerm:(NSString *) searchTerm {
for (int i=0; i < [dataSource count]; i++) {
    NSString *temp = [dataSource objectAtIndex:i]
    if ([temp isEqualToString:searchTerm]) {
        int selectedIndex = i;
        break;
    }
}
return selectedIndex;
}
And to use this method, you would simply call:
[tableView scrollToRowAtIndexPath:[self indexForSearchTerm:@"whatever word you're looking for"] atScrollPosition:UITableViewScrollPositionTop animated:YES];
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论