Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I created a custom table cell that expands. When it expands, it shows a UILabel along with two UIButtons. The UILabel should show data from the backend. I created the customLabel in the CustomCell interface file. Then I imported the CustomCell class into my InboxTableViewController, and implemented the custom cell. The label only appears when the cell is tapped, and expands. How would I go about changing the UILabel, because cell.customLabel.text, would not work here, since it is not a property of the cell. Here is the associated code:

CustomCell.h


@interface CustomCell : UITableViewCell
{
UIImage *userImage;
UILabel *userName;

//below widgets will display when user tapped
  @public
UIButton *leftButton, *rightButton;
UILabel *customLabel;
BOOL userTapped;
}
@property (weak, nonatomic) IBOutlet UILabel *userName;

@property (weak, nonatomic) IBOutlet UIImageView *userImage;



- (void) setData:(NSDictionary*) d;

@end

and here is the inboxviewcontroller.m where i try to implement the customcell along with the customLabel.

:
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath  *)indexPath
{
 static NSString *CellIdentifier = @"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (!cell) {
    cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
 //  PFObject *message = [self.messages objectAtIndex:indexPath.row];

PFObject *message = [self.messages objectAtIndex:indexPath.row];

cell.userName.text = [message objectForKey:@"from"];
//cell.userImage.image = [message objectForKey:@"image1"];
cell.customLabel.text =  [message objectForKey:@"message"];

return cell;}
share|improve this question
    
how are you expanding the cell in order to show the label, make the cell in such a way, that the label becomes its property –  Geet 2 hours ago

1 Answer 1

This will not work as you are creating instance of CustomCell directly instead you have to load CustomCell view from nib so it will create instance of customLabel and using this you can set text, use below code

CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
            NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil];
            cell=[nib objectAtIndex:0];
        }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.