【问题标题】:Access text from UILabel that is set as AccessoryView to a UITableView从设置为 AccessoryView 的 UILabel 访问文本到 UITableView
【发布时间】:2014-04-15 07:30:20
【问题描述】:

UITableView 使用UILabel 作为其Accessory View

通过使用下面的代码,我可以检索到UILabel,但我不知道如何单独访问文本:

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

日志:

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

我想单独检索文本('12:50 PM')。谢谢!

【问题讨论】:

    标签: ios uitableview uiaccessoryview


    【解决方案1】:
    NSLog(@"text label: %@",((UILabel*)[[self.frequencyTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] accessoryView]).text);
    

    但是,这并不是很安全,我相信直接访问您的模型会更好,当您设置附件视图时,您应该执行以下操作:

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

    如果你想要文本直接从你的数组中获取它

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

    【讨论】:

      【解决方案2】:

      试试这个

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

      【讨论】:

        猜你喜欢
        • 2020-04-04
        • 1970-01-01
        • 2023-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多