Reputation: 1248
I have a tableView with a custom cell which consists of 3 labels, name, book and chapter. Unfortunately it seems like my cell is not big enough for the 3 labels and I want to make it bigger. What should I do in my code below to achieve this in the best way? /Regards
Picture of the cell's in the tableView: http://tinypic.com/view.php?pic=2vrzpu9&s=6
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"BookmarkCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Bookmark *item = [self.items objectAtIndex:indexPath.row];
NSArray *chunks = [item.name componentsSeparatedByString: @","];
NSString *name;
NSString *book;
NSString *chapter;
if ([chunks count] > 0)
{
name = [chunks objectAtIndex:0];
if ([chunks count] > 1)
{
book = [chunks objectAtIndex:1];
if ([chunks count] > 2)
{
chapter = [chunks objectAtIndex:2];
}
}
}
UIView * pNewContentView= [[UIView alloc] initWithFrame:cell.contentView.bounds];
CGRect labelFrame= pNewContentView.bounds;
labelFrame.size.height= labelFrame.size.height * 0.25;
UILabel* pLabel1=[[UILabel alloc] initWithFrame:labelFrame];
[pNewContentView addSubview:pLabel1];
labelFrame.origin.y= labelFrame.size.height;
UILabel* pLabel2=[[UILabel alloc] initWithFrame:labelFrame];
[pNewContentView addSubview:pLabel2];
labelFrame.origin.y= labelFrame.origin.y + labelFrame.size.height;
UILabel* pLabel3=[[UILabel alloc] initWithFrame:labelFrame];
[pNewContentView addSubview:pLabel3];
[cell.contentView addSubview:pNewContentView];
[pLabel1 setText:(name)];
[pLabel2 setText:(book)];
[pLabel3 setText:(chapter)];
//cell.textLabel.text = chapter;
//cell.textLabel.text = name;
//cell.detailTextLabel.text = book;
return cell;
}
Upvotes: 0
Views: 130
Reputation: 3937
its easy to customize the height of a UITableViewCell
just add the delegate method
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
return 70; // or whatever height you need
}
Upvotes: 4