简体   繁体   中英

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);

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.

:-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM