Get cell's textLabel.text from a cell in UISearchDisplayController?
When I'm getting the cell's textLabel.text in a regular tableView (in the didSelectRowAtIndexPath method) I do (and it works!):
UITableViewCell *cell = (UITableViewCell *)[(UITableView *)self.view cellForRowAtIndexPath:indexPath];
NSLog(@"Cell's text: %@",cell.textLabel.text);
开发者_Python百科
this doesn't work when I click a cell in my UISearchDisplayController. When I push a next view controller in that method, it will push. But I'm always getting "null" for the cell.textLabel.text.
What am I doing wrong?
Thanks a lot in advance!!!
With the help of the guys from iphonedevsdk.com I figured out that this code works:
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSLog(@"Cell's text: %@",cell.textLabel.text);
This is because what the previous code does, is that it is accessing the tableView from the view controller, not the UISearchDisplayController's tableView. This code can access both tableViews.
:-)
精彩评论