【问题标题】:UITableView not displaying correctly on iPadUITableView 在 iPad 上无法正确显示
【发布时间】: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


【解决方案1】:

子类化 UITableViewCell 解决了对齐问题。

关于当视图在 iPad 上弹出时的那个白色箭头,我设法改变了它的颜色:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.popoverPresentationController.backgroundColor = [UIColor colorWithRed:(23/255.0) green:(23/255.0) blue:(23/255.0) alpha:1.0];
}

此 viewWillAppear 属于弹出框中显示的 UITableViewController。

感谢您的建议

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-18
    • 1970-01-01
    • 2019-07-13
    • 2016-09-09
    • 2014-05-16
    相关资源
    最近更新 更多