开发者

Get cell's textLabel.text from a cell in UISearchDisplayController?

开发者 https://www.devze.com 2023-04-06 17:30 出处:网络
When I\'m getting the cell\'s textLabel.text in a regular tableView (in the didSelectRowAtIndexPath method) I do (and it works!):

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.

:-)

0

精彩评论

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

关注公众号