UITableView некорректно отображается на iPad

#ios #objective-c #ipad #ios-simulator #xcode8

#iOS #objective-c #iPad #ios-симулятор #xcode8

Вопрос:

На 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;
}
  

Спасибо за вашу помощь.

Комментарии:

1. Обратите внимание, что [cell.contentView addSubview:ttitle] это не рекомендуется, поскольку ячейки используются повторно. Вместо этого почему бы не использовать пользовательскую ячейку?

2. Это может решить проблему с положением UILabel в ячейке. Но где я действительно заблудился, так это в tableview, оставленном на iPad:(

3. это плохой пользовательский интерфейс. вы продолжаете добавлять представление при прокрутке до первого раздела. создайте подкласс uitableviewcell и выполните инициализацию пользовательского интерфейса там. в ячейке для строки просто удалите из очереди зарегистрированную ячейку и обновите метку или что-то еще.

4. Спасибо Ларме и Джошуа, подклассы решили проблемы с выравниванием.

Ответ №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, который показан во всплывающем окне.

Спасибо за ваши предложения