IOS UITableViewCells在第一个小区,Iphone5S设备中都混乱,64位模拟器

Mir*_*iro 3 uitableview ios

我有一个表现奇怪的UITableView.具体来说,它在cellForRowAtIndexPath中生成了一个常数8个单元格,带有一些基本文本和图像.在模拟器中它很棒.在我的Iphone5上,它的工作方式与模拟器完全相同,但是在我的Iphone5s上,单元格在第一个单元格应该存在的地方互相混淆.下面的图像分别显示5s和模拟器/ 5.左侧"退出应用程序"按钮应存在于最后一个单元格中,并且正在添加到其他内容之上,也由箭头指示.

编辑:第三个图像是64位模拟器,更新的cellForRowAtIndexPath是超简化的,只需将textLabel设置为所有8行的"Hello".

Autolayout未在应用程序的任何位置使用.

Iphone 5S正在运行IOS7.1.1,但Iphone5正在运行IOS7.1.模拟器是最新Xcode(5.1.1)的一部分,最新的7.1.我无法想象5s的最新.1可能会导致这种情况.

有什么想法为什么这是混乱的,具体为什么只有在5S?

iPhone 5S iphone5或模拟器 64位

- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 8;
}

- (float)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {
    float height =  self.view.frame.size.height / [self tableView:tableView numberOfRowsInSection:indexPath.section];
    return height;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *CellIdentifier = @"CellMain";

    UITableViewCell *_cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (_cell == nil) {
        _cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
         _cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *user_fullname = [userDefaults valueForKey:@"user_fullname"];

    _cell.textLabel.textColor = [UIColor colorWithHexString:@"58A5D5"];
    _cell.detailTextLabel.textColor = [UIColor colorWithHexString:@"58A5D5"];
    if(indexPath.row == 0){
        _cell.textLabel.text = [NSString stringWithFormat:@"%@",@"User Name"];//user_fullname];
        _cell.detailTextLabel.text = [NSString stringWithFormat:@"Member since: %@", @"April 28, 2014"];
        _cell.imageView.image = [UIImage imageNamed:@"profile_photo.png"];
        _cell.imageView.contentMode = UIViewContentModeScaleAspectFit;

        UIImageView *arrowImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_right.png"]];
        arrowImg.frame = CGRectMake(292, 14, 18, 30);
        [_cell.contentView addSubview:arrowImg];
    } else if(indexPath.row == 1){
        _cell.textLabel.text = [NSString stringWithFormat:@"ActivitySync"];
        _cell.detailTextLabel.text = [NSString stringWithFormat:@"Last sync: %@", @"5 minutes ago"];
        _cell.imageView.image = [UIImage imageNamed:@"iphone_sm.png"];
        _cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
    } else if(indexPath.row == 2){
        _cell.contentView.backgroundColor = [UIColor colorWithHexString:@"D9DBDB"];
    } else if(indexPath.row == 3){
        _cell.textLabel.text = [NSString stringWithFormat:@"%@",@"Challenges"];
        UIImageView *arrowImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_right.png"]];
        arrowImg.frame = CGRectMake(292, 14, 18, 30);
        [_cell.contentView addSubview:arrowImg];
    } else if(indexPath.row == 4){
        _cell.textLabel.text = [NSString stringWithFormat:@"%@",@"Setup a New Device"];
        UIImageView *arrowImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_right.png"]];
        arrowImg.frame = CGRectMake(292, 14, 18, 30);
        [_cell.contentView addSubview:arrowImg];
    } else if(indexPath.row == 5){
        _cell.textLabel.text = [NSString stringWithFormat:@"%@",@"Help"];
        UIImageView *arrowImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_right.png"]];
        arrowImg.frame = CGRectMake(292, 14, 18, 30);
        [_cell.contentView addSubview:arrowImg];
    } else if(indexPath.row == 6){
        _cell.contentView.backgroundColor = [UIColor colorWithHexString:@"D9DBDB"];
    } else if(indexPath.row == 7){
        UIButton *logout = [[UIButton alloc] initWithFrame:CGRectMake(10, 9, 300, 39)];
        [logout setTitle:@"Log Out of App" forState:UIControlStateNormal];
        logout.titleLabel.textColor = [UIColor colorWithHexString:@"58A5D5"];
        [logout addTarget:self action:@selector(logoutBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [_cell.contentView addSubview:logout];
    }

    return _cell;
}
Run Code Online (Sandbox Code Playgroud)

jrt*_*ton 11

返回CGFloat,而不是float从你的heightForRow方法返回.这是一个64位问题 - 类型在那里定义不同.我认为返回一个浮点值会导致64位设备中的高度被视为零.

您需要更改方法的返回类型以及其中的声明.不要float用于UIKit的东西,它总是CGFloat.