views:

155

answers:

2

I have a custom UITableViewCell which I have created in IB. My labels display when I don't over-ride:

- (CGFloat)tableView:(UITableView *)tblView heightForRowAtIndexPath:(NSIndexPath *)indexPath

however my content is squished. I want the height to be 120px so I have the following:

- (CGFloat)tableView:(UITableView *)tblView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{   CGFloat rowHeight = 120;
    return rowHeight;
}

I'm not sure why the content inside of my UITableViewCell all of a sudden disappears?

UPDATE: Here is how I create the cell:

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

    static NSString *MyIdentifier = @"ARCell";
    ARObject *myARObject;
    myARObject = [items objectAtIndex:indexPath.row];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"ARCell" owner:self options:nil];
        cell = arCell;
        self.arCell = nil;
    }

    UILabel *label;
    label = (UILabel *)[cell viewWithTag:0];
    label.text = [NSString stringWithFormat:@"%@", myARObject.username];

    label = (UILabel *)[cell viewWithTag:1];
    label.text = [NSString stringWithFormat:@"%@", myARObject.created_at];

    label = (UILabel *)[cell viewWithTag:2];
    label.text = [NSString stringWithFormat:@"%@", myARObject.articleTitle];

    label = (UILabel *)[cell viewWithTag:3];
    label.text = [NSString stringWithFormat:@"%@", myARObject.intro_text];

    return cell;
}
A: 

within IB did you set the height of the view size there too?

if so you could just try to return 120 opposed to declaring it as a CGFloat

edit: one other thought, make sure you save in IB... thats the leading cause of display bugs!

cdnicoll
Under the Size Tab in IB I set W: 320 and H: 120 is this the correct place?
Sheehan Alam
A: 

I think there is something fishy going on with how you're loading the nib for the tableview cell. Instead of connecting the cellview to an outlet on the file's owner, why don't you try something like:

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ARCell" owner:self options:nil];
        cell = (UITableViewCell *)[nib objectAtIndex:0];

At the very least I recommend you debug and set a breakpoint on that line to verify that

  1. the cell really exists
  2. the cell has the subviews you expect
  3. the cell has the right frame and bounds for the tableview cell
fbartho