微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我有一个表现奇怪的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?

- (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,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,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,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;
}

解决方法

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐