UITableViewCell宽度大于UITableView宽度

use*_*469 5 objective-c uitableview ios

我遇到了一个奇怪的问题.我正在为我的tableviews创建自定义选定视图.但是,此选择视图不适合.我发现这是因为我的选择视图是300px,而单元格本身是320px.奇怪的是,它UITableView的宽度实际上只有300px.如何调整桌子的格子宽度?

- (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;
}
Run Code Online (Sandbox Code Playgroud)

Ivo*_*beg 4

刚刚设置

cell.frame = CGRectMake(0,
                        0,
                        self.tableView.frame.size.width,
                        cell.frame.size.height);
Run Code Online (Sandbox Code Playgroud)

cellForRowAtIndexPath