Setting Labels on custom UITableViewCells NIBs

Discussion in 'iOS Programming' started by newDeveloper, Jul 14, 2010.

  1. newDeveloper macrumors newbie

    Jun 13, 2010
    I have created a grouped table view in a program and configured it to 1 section and 4 rows, where I pull in a custom cell that I created (UITableViewCell) using a NIB file, as so...

    if (indexPath.section == 0)
    		cell = [tableView dequeueReusableCellWithIdentifier:@"firstlevelcell"];
    		if (!cell)
    			cell = [[[NSBundle mainBundle] loadNibNamed:@"firstlevelcell" owner:self options:nil] lastObject];
    			cell.selectionStyle = UITableViewCellSelectionStyleNone;
    Now, I want to use that "firstlevelcell" throughout my application in different places, but for this view, I want to use it four times in a row, and change the label to four different values I have stored in an array [0-3].

    I feel like if I create an outlet, I have to change the class of the UITableViewCell nib from NSObject to my custom subclass to tie it to that outlet...but that would mean I have to create multiple copies of that NIB if I want to use it elsewhere in the application.

    How do I change the value of the labels in that custom NIB when I load it, so that I can use that NIB all over the application???

    Does that make sense?
  2. newDeveloper thread starter macrumors newbie

    Jun 13, 2010
    So I added...

    cell.textLabel.text = @"newDeveloper"; the code so that I can set the values...but how do I do that with creating code for each row...since it uses the same nib? Can I just cycle through my array using enumeration for 0 through [array count] and modify the above code to...

    cell.textLabel.text = [array objectAtIndex:X];


Share This Page