0

I have a TableView that i populate with custom cells. In this code i would like to set the data on my different labels, but it doesnt seem to work. I can not add any outlets, not sure why i cant do that. When i try to change the data with cell.textLabel.text = @"Data"; it seems to add a new label instead of changing the text of the current one.

What should i do? Code below shows how i populate the list.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ 
    SenasteTableCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:CellIdentifier];
    if(cell == nil)
    {
        NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"SenasteTableCell" owner:nil options:nil];

        for (UIView *view in views)
        {
            cell = (SenasteTableCell*)view;
        }
    }
    return cell;
}
UdayM
  • 1,725
  • 16
  • 34
Lord Vermillion
  • 5,264
  • 20
  • 69
  • 109

3 Answers3

1

Set a unique tag to the label in customcell and you can get its instance as

     UILabel *Label=(UILabel *)[cell viewWithTag:2];//2 is th unique tag value i set in the cell for that label

You can get value for every view objects in the cell like this

Eg

     UIButton *sampleButton=(UIButton *)[cell viewWithTag:4];
Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
0

You should be able to create outlets. If you are using a custom table view cell (which Im assuming SenasteTableCell is) make sure that in the interface builder you click on the cell and set its class to SenasteTableCell. At that point you should be able to control drag from your labels to the file and create outlets.

grodier
  • 101
  • 4
0

I think you have not set the FileOwner Property form XIB file. set fileowner as UITableViewClass and UITableViewCell As SenasteTableCell. To connect outlets you have to first select SenasteTableCell and there will be a list of oulets.

Prateek Prem
  • 1,544
  • 11
  • 14