简体   繁体   English

从设置为AccessoryView的UILabel访问文本到UITableView

[英]Access text from UILabel that is set as AccessoryView to a UITableView

A UITableView uses a UILabel as its Accessory View . UITableView使用UILabel作为其Accessory View

By using the following code, I am able to retrieve the UILabel but i cant figure how to access the text alone: 通过使用以下代码,我能够检索UILabel但是我无法弄清楚如何单独访问文本:

NSLog(@"text label: %@",[[self.frequencyTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] accessoryView]);

LOG: 日志:

2014-04-15 12:50:16.433 SmartWatch[2771:70b] text label: <UILabel: 0xfb81870; frame = (205 4; 60 20); text = '12:50 PM'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0xfb619d0>>

i want to retrieve the text alone('12:50 PM').Thanks! 我想单独检索文本(“下午12:50”)。谢谢!

NSLog(@"text label: %@",((UILabel*)[[self.frequencyTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] accessoryView]).text);

However, this is not really secure, i believe it would be better to directly access your model, when you set your accessory view you should do something like : 但是,这并不是真的安全,我相信直接访问您的模型会更好,当您设置附件视图时,您应该执行以下操作:

UILabel *label = [[UILabel alloc] init];
label.text = [someArray objectAtIndex:indexPath.row];
cell.accessoryView = label;

And if you want the text just get it directly from your array 如果您想直接从数组中获取文本

NSLog(@"text label: %@",[someArray objectAtIndex:0]);

尝试这个

NSLog(@"text label: %@",((UILabel*)[[self.frequencyTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] accessoryView]).text);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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