【发布时间】:2017-03-01 10:09:05
【问题描述】:
在 iPhone 上,tableview 看起来不错,但在 iPad(模拟器 ios10)中,它是这样显示的:
在此处查看图片:http://welove.pt/img/ipadtrouble.png
知道为什么它在 iPhone/iPad 上的显示方式不同吗? 另外,搜索图标旁边的那个白角是怎么回事?为什么不是黑色的?
ViewDidLoad:
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.separatorColor = [UIColor colorWithRed:58/255.0 green:58/255.0 blue:58/255.0 alpha:1.0];
_tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);
_tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
[self.view addSubview:_tableView];
cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
UIView *selectionColor = [[UIView alloc] init];
selectionColor.backgroundColor = [UIColor colorWithRed:(54/255.0) green:(54/255.0) blue:(54/255.0) alpha:1];
cell.selectedBackgroundView = selectionColor;
cell.backgroundColor = [UIColor colorWithRed:(28/255.0) green:(28/255.0) blue:(28/255.0) alpha:1];
cell.textLabel.textColor = [UIColor whiteColor];
}
if (indexPath.section == 0) {
cell.imageView.image = [[UIImage imageNamed:@"defineLocation.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UILabel *ttitle = [[UILabel alloc] initWithFrame:CGRectMake(46, 12, 320, 20)];
ttitle.font = [UIFont systemFontOfSize:17];
ttitle.textColor = [UIColor colorWithRed:(115/255.0) green:(229/255.0) blue:(69/255.0) alpha:1.0];
[ttitle setText:NSLocalizedString(@"current_location", nil)];
[cell.contentView addSubview:ttitle];
} else {
cell.textLabel.text = [[_recentSearchData objectAtIndex:indexPath.row] objectForKey:@"recentTitle"];
}
return cell;
}
感谢您的帮助。
【问题讨论】:
-
请注意,
[cell.contentView addSubview:ttitle]不建议使用,因为单元格会被重复使用。相反,为什么不使用自定义单元格? -
这可以解决单元格上的 UILabel 位置。但我真正迷失的地方是 iPad 上左侧的表格视图 :(
-
这是糟糕的用户界面。当您滚动到第一部分时,您会继续添加视图。创建一个 uitableviewcell 子类并在那里进行 UI 初始化。在行的单元格中,只需将已注册的单元格出列并更新标签或其他内容。
-
感谢 Larme 和 Joshua,子类化解决了对齐问题。
标签: ios objective-c ipad ios-simulator xcode8