views:

36

answers:

2

This is my program

  - (void)viewDidLoad {
    [super viewDidLoad];

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    self.title = @"Library";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStyleBordered target:self action:@selector(close:)];
   // self.tableView.rowHeight = 80;
    }

-(void)close:(id)sender
{
//
}


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

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) 
{   cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

    UILabel *dateLabel = [[UILabel alloc]init];
    dateLabel.frame = CGRectMake(85.0f, 6.0f, 200.0f, 20.0f);
    dateLabel.tag = tag1;
    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    cell.contentView.frame = CGRectMake(0.0f, 0.0f, 320.0f, 80.0f);
    [cell.contentView addSubview:dateLabel];
    [dateLabel release];
}

// Set up the cell...
//[(UILabel *)[cell viewWithTag:tag1] setText:@"Date"];
cell.textLabel.text = @"Date";

return cell;
}  

I am setting the frame size of cell in tableView: but the cell is in default size only. I mean the height I set was 80 but it was not set as 80 height. How can I make it.

Thank You

+1  A: 

tableView:cellForRowAtIndexPath: is only called if tableView:numberOfRowsInSection: returns a positive value. Your code looks fine, although you should not need to set the frame of the contentView.

drawnonward
I need to add image and 6 labels in each cell. So, I am using the set frame. Thank You.
srikanth rongali
I think that the cell and contentView frames are both automatically sized by the table view based on the rowHeight and table width.
drawnonward
+1  A: 

Use self.tableView.rowHeight = 80.0;, or if that's not working (depends on your table view setup), use the -[UITableViewDelegate tableView:heightForRowAtIndexPath:] method if you want different row heights for different cells.

e.g. put this in whatever object is your UITableViewDelegate (probably the same file as above).

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (someConditionBasedOnIndexPath) return 60.0;
    return 80.0;
}
Nick Forge
Thank You.It worked. I used-[UITableViewDelegate tableView:heightForRowAtIndexPath:]
srikanth rongali