0

A UITableView uses a UILabel as its Accessory View.

By using the following code, I am able to retrieve the UILabel but i cant figure how to access the text alone:

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!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
motox
  • 759
  • 10
  • 17

2 Answers2

1
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]);
voidStern
  • 3,678
  • 1
  • 29
  • 32
streem
  • 9,044
  • 5
  • 30
  • 41
0

Try this

NSLog(@"text label: %@",((UILabel*)[[self.frequencyTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] accessoryView]).text);
Anand Suthar
  • 3,678
  • 2
  • 30
  • 52