UITableViewCell width is greater than UITableView width

ios, objective-c, uitableview

Solution

Just set

cell.frame = CGRectMake(0,
                        0,
                        self.tableView.frame.size.width,
                        cell.frame.size.height);

in `cellForRowAtIndexPath`.

Problem

I encountered a weird problem. I am creating a custom selected view for my tableviews. However, this selection view doesn't fit well. I found out that this is because my selection view is 300px while the cell itself is 320px. The weird part is that the `UITableView`'s width is actually just 300px only. How will I adjust the cell width of my table? ``` - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *tableIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier]; if (cell == nil) cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier] autorelease]; if (tableView == bandTable) { UIImageView *imageBg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"column1_selected.png"]]; [imageBg setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; [cell setSelectionStyle:UITableViewCellSelectionStyleGray]; [cell setSelectedBackgroundView:imageBg]; [imageBg release]; NSArray *array = [bandDictionary objectForKey:@"Bands"]; cell.textLabel.text = [array objectAtIndex:indexPath.row]; NSLog(@"CELL: %f", cell.bounds.size.width); } return cell; } ```

Original source