我一直在将应用从iOS6转换为iOS7,使用以下代码在UITableviewController
中显示单元格:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PCApplicationCell *cell = (PCApplicationCell*)[tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil)
{
if(indexPath.section == 0 || indexPath.section == 2)
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone || self.PopOver)
self.cellNib = [UINib nibWithNibName:@"PCChooseSubviewsBasedApplicationCell_iPhone" bundle:nil];
else
self.cellNib = [UINib nibWithNibName:@"PCChooseSubviewsBasedApplicationCell_iPad" bundle:nil];
}
else
{
if(indexPath.row == 1)
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone || self.PopOver)
self.cellNib = [UINib nibWithNibName:@"PCEditSubviewsBasedApplicationCell_iPhone" bundle:nil];
else
self.cellNib = [UINib nibWithNibName:@"PCEditSubviewsBasedApplicationCell_iPad" bundle:nil];
}
else
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone || self.PopOver)
self.cellNib = [UINib nibWithNibName:@"PCSwitchSubviewsBasedApplicationCell_iPhone" bundle:nil];
else
self.cellNib = [UINib nibWithNibName:@"PCSwitchSubviewsBasedApplicationCell_iPad" bundle:nil];
}
}
[self.cellNib instantiateWithOwner:self options:nil];
cell = tmpCell;
self.tmpCell = nil;
[cell setDelegate:self];
}
// get the view controller's info dictionary based on the indexPath's row
NSDictionary* itemSection = [self.listContent objectAtIndex:indexPath.section];
NSArray* groupItems = [itemSection objectForKey:kChildrenKey];
NSDictionary* item = [groupItems objectAtIndex:indexPath.row];
cell.help = [item objectForKey:kItemHelpKey];
cell.helpcontents = [item objectForKey:kHelpChildrenKey];
cell.tag = indexPath.row;
cell.name = [item objectForKey:kItemTitleKey];
cell.value = @"";
if(indexPath.section == 1)
{
if(indexPath.row == 1)
{
cell.value = [NSString stringWithFormat:@"%d ", [config.MDepthIntervalInTCPlot intValue]];
cell.tag = 0;
}
else
{
UISwitch *switchControl = [[UISwitch alloc] initWithFrame:CGRectMake(1.0, 1.0, 20.0, 20.0)];
[switchControl addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
if([config.MDepthsInTCPlot boolValue])
switchControl.On = YES;
else
switchControl.On = NO;
switchControl.tag = 0;
cell.accessoryView = switchControl;
switchControl = nil;
}
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
此处可以看到UITableView
与UINavigationController
作为父级,然后是popover之间的差异:
请注意,即使我在实验中,也无法在popover版本中看到Disclosure箭头 随着popover宽度的增加。 popover中的单元格使用iPhone宽度。 另请注意单元格中标签的格式不正确,但定位 好吗?
在原始iOS6版本中,popover版本显示UINavigationController
版本的相同格式。
答案 0 :(得分:0)
解决方法:添加:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundColor = [UIColor whiteColor]; }