开发者

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜