HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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.

大佬总结

以上是大佬教程为你收集整理的IOS UITableViewCells在第一个小区,Iphone5S设备中都混乱,64位模拟器全部内容,希望文章能够帮你解决IOS UITableViewCells在第一个小区,Iphone5S设备中都混乱,64位模拟器所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。