Karuppu MGR Karuppu MGR - 6 months ago 22
Objective-C Question

Values for uilabels of custom tableview cell is not being set

Im using a tableview with custom cells.

Following is my cellForRowAtIndexPath method.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

// AssigneeCell *cell = (AssigneeCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"];

static NSString *cellIdentifier = @"Cell";
AssigneeCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (!cell)
{
[tableView registerNib:[UINib nibWithNibName:@"AssigneewiseView" bundle:nil] forCellReuseIdentifier:@"Cell"];
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

NSLog(@"call");
}

cell.unitNameVal = unitNameResult[indexPath.row];
cell.domainNameVal = domainNameResult[indexPath.row];
cell.compliedVal = compliedResult[indexPath.row];
cell.delayedVal = delayedResult[indexPath.row];
cell.inProgressVal = inProgressResult[indexPath.row];
cell.notCompliedVal = notCompliedResult[indexPath.row];
cell.totalVal = totalValResult[indexPath.row];

return cell;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

return [compliedResult count];
}


numberOfRowsInSection is called and hence my tableview contains multiple views depending upon the count of compliedResult.

But the problem is that, the values for uilabels present in my custom cell is not being assigned and hence its not visible. Why is that so?

Answer

Since unitNameVal, domainNameVal, etc. are labels, make sure you are setting their text property. What you are doing right now is setting the labels themselves as different objects.

Assuming your arrays are arrays of strings, this should do the trick for you:

cell.unitNameVal.text = unitNameResult[indexPath.row];
cell.domainNameVal.text = domainNameResult[indexPath.row];
...