0

Apologies if this comes across as a beginner's question. I'm trying to populate a UITableView with sections and custom cell formatting.

i've debug this code and the label on each tag returns the correct value:

-(UITableViewCell *)cellForIndexPath:(NSIndexPath *)indexPath forData:(NSObject *)cellData {
static NSString *CellIdentifier = @"MatterWIPCell";

RVMatterWIPExceptionSummary *matterWIPSummary = (RVMatterWIPExceptionSummary *)cellData;

UITableViewCell *cell = [self.searchableTable dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

UILabel *label;

label = (UILabel *)[cell viewWithTag:1];
label.text = [[DataFormat dataFormat] stringLabelFormat: matterWIPSummary.fileNumber];

label = (UILabel *)[cell viewWithTag:2];
label.text = [[DataFormat dataFormat] stringLabelFormat: matterWIPSummary.clientName];

label = (UILabel *)[cell viewWithTag:3];
label.text = [[DataFormat dataFormat] stringLabelFormat: matterWIPSummary.matterTitle];

label = (UILabel *)[cell viewWithTag:4];
label.text = [[DataFormat dataFormat] currencyFormat:matterWIPSummary.workInProgress withDecimals:YES];

label = (UILabel *)[cell viewWithTag:5];
label.text = [[DataFormat dataFormat] stringLabelFormat:matterWIPSummary.matterDescription];

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;

}

i have checked the storyboard it uses the same cell identifier.

Did i miss something so the data won't display even the cell never returns nil?

Thank You

Yuka Fujisaku
  • 21
  • 1
  • 8
  • 1
    The text isn't being set. You have to say `cell.textLabel.text = label.text`. The label is just sitting there, not part of the cell. – charleyh May 27 '13 at 01:33
  • but i set label = (UILabel *)[cell viewWithTag:]; it means on the storyboard to set the value into the right label on the table view cell isn't it? it works on the other class but not in this class – Yuka Fujisaku May 27 '13 at 01:39
  • You're making a copy of it right then with the same values, but they change one and you don't change the other. So you need to set it at the end. – charleyh May 27 '13 at 01:43
  • i have tried using cell.textLabel.text = label.text but it still won't appear. – Yuka Fujisaku May 27 '13 at 01:59
  • Try this: comment out all of the `label = (UILabel *)[cell viewWithTag:1]; label.text = [[DataFormat dataFormat] stringLabelFormat: matterWIPSummary.fileNumber];` lines and do `cell.textLabel.text = @"Text";` or something like that and see what happens. – charleyh May 27 '13 at 02:05
  • nothing happen.. it is still not displaying anything. – Yuka Fujisaku May 27 '13 at 02:32
  • Do some logging. If after the line label = (UILabel *)[cell viewWithTag:1];, you log label, what does it return? After the next line, if you log label.text, what does it return? – rdelmar May 27 '13 at 03:03
  • It is return the correct value of the label, but the label won't display on the simulator. as i investigate more it return nil for the visible cell but the cell return the correct value. i don't know how it can be happen – Yuka Fujisaku May 27 '13 at 04:02
  • I'm sorry it's because my own mistake. i have checked the code is correct. Something missing in another method i called `[self.searchableTable SetHidden: YES]` it makes the visible cell returns nil. – Yuka Fujisaku May 27 '13 at 05:55
  • You actually haven't mentioned what your problem is. Does the table view appear empty, or are some cells aren't being displayed? – Matt May 27 '13 at 19:08

1 Answers1

-1

Add [cell.contentView addSubview:label]; before the return cell; And of course declare label with something like this UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 320, 25)];

nerowolfe
  • 4,787
  • 3
  • 20
  • 19