views:

362

answers:

2

I am having trouble in accessing which is in the UITableViewCell, that i have placed in my main .xib file.

That Label is connected to IBOutlet servicesCell.

And the Label inside the table view cell is connected through IBOutlet serviceLabel.

At runtime i am not getting the text which i am assining to that label.

Following is my sample code for that.

static NSString *ServiceIdentifier = @"ServiceIdentifier";

UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:ServiceIdentifier];

if(cell1 == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"servicesCell" owner:self options:nil];
    cell1 = servicesCell;
}

// label access
serviceLabel = (UILabel *)[cell1 viewWithTag:1];
serviceLabel.numberOfLines = 3;
serviceLabel.lineBreakMode = UILineBreakModeWordWrap;
[serviceLabel setTextAlignment:UITextAlignmentLeft];
[serviceLabel setText:@"Testing String"];

Anyone have any idea then please help..

Thanks in advance..

A: 

Place the UITableViewCell in it's own nib.

zaph
+1  A: 

You say that your Cell is in your main XIB file, but I take it the cell is actually in "servicesCell.xib", correct?

I assume you started with "Loading Custom Table-View Cells from Nib Files". This code is similar to Apple's example, so I assume you started there. If you just copied this code from somewhere without understanding it, go read that doc first.

You should walk through this code in the debugger and make sure that everything is set to what you think it should be set to. The most common cause of "nothing happens" is that you're sending messages to nil, and so I bet one of your variables here is actually nil. Looking at this code, the most likely culprits are failure to actually wire something in IB (this is the most common cause of nil objects when working with NIBs; double check that you really did it), or that you have not assigned your label the expected tag of 1.

Rob Napier