草庐IT

IOS UITableViewCells 都混杂在第一个单元格中,尽管只有 Iphone5S 设备,64 位模拟器

coder 2023-10-01 原文

我有一个行为异常的 UITableView。具体来说,它有一个恒定的 8 个单元格,在 cellForRowAtIndexPath 中生成,带有一些基本的文本和图像。在模拟器中效果很好。在我的 Iphone5 上,它的工作方式与模拟器相同,但是在我的 Iphone5s 上,单元格都在第一个单元格应该存在的地方相互重叠。下图分别显示了 5s 和 simulator/5。左边的“退出应用程序”按钮应该存在于最后一个单元格中,并且被添加到其他内容之上,也由箭头指出。

编辑:第三张图片是 64 位模拟器,更新后的 cellForRowAtIndexPath 被 super 简化为仅将所有 8 行的 textLabel 设置为“Hello”。

应用中的任何地方都没有使用自动布局。

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

最佳答案

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

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

关于IOS UITableViewCells 都混杂在第一个单元格中,尽管只有 Iphone5S 设备,64 位模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23570068/

有关IOS UITableViewCells 都混杂在第一个单元格中,尽管只有 Iphone5S 设备,64 位模拟器的更多相关文章

  1. ruby - 在 64 位 Snow Leopard 上使用 rvm、postgres 9.0、ruby 1.9.2-p136 安装 pg gem 时出现问题 - 2

    我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po

  2. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  3. C# 到 Ruby sha1 base64 编码 - 2

    我正在尝试在Ruby中复制Convert.ToBase64String()行为。这是我的C#代码:varsha1=newSHA1CryptoServiceProvider();varpasswordBytes=Encoding.UTF8.GetBytes("password");varpasswordHash=sha1.ComputeHash(passwordBytes);returnConvert.ToBase64String(passwordHash);//returns"W6ph5Mm5Pz8GgiULbPgzG37mj9g="当我在Ruby中尝试同样的事情时,我得到了相同sha

  4. 【鸿蒙应用开发系列】- 获取系统设备信息以及版本API兼容调用方式 - 2

    在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList​()Obt

  5. ruby-on-rails - 禁用设备的 :confirmable on-the-fly to batch-generate users - 2

    Devise是一个Ruby库,它为我提供了这个User类:classUser当写入:confirmable时,注册时会发送一封确认邮件。上周我不得不批量创建300个用户,所以我在恢复之前注释掉了:confirmable几分钟。现在我正在为用户批量创建创建一个UI,因此我需要即时添加/删除:confirmable。(我也可以直接修改Devise的源码,但我宁愿不去调和它)问题:如何即时添加/删除:confirmable? 最佳答案 WayneConrad的解决方案:user=User.newuser.skip_confirmation

  6. ruby-on-rails - CarrierWave - PDF - 只选择第一页 - 2

    我的Rails应用程序中安装了carrierwave。但是,当用户上传多页pdf时,我只希望应用程序获取文档中的第一页并将其转换为jpeg。这可能吗?用什么命令?这是我的uploader。#encoding:utf-8classImageUploader[200,300]##defscale(width,height)##dosomething#end#Createdifferentversionsofyouruploadedfiles:version:thumbdoprocess:resize_to_fill=>[150,210]process:convert=>:jpgdefful

  7. ruby - 如何跳过 CSV 文件的第一行并将第二行作为标题 - 2

    有没有办法跳过CSV文件的第一行,让第二行作为标题?我有一个CSV文件,第一行是日期,第二行是标题,所以我需要能够在遍历它时跳过第一行。我尝试使用slice但它会将CSV转换为数组,我真的很想将其读取为CSV,以便我可以利用header。 最佳答案 根据您的数据,您可以使用另一种方法和skip_lines-option此示例跳过所有以#开头的行require'csv'CSV.parse(DATA.read,:col_sep=>';',:headers=>true,:skip_lines=>/^#/#Markcomments!)do|

  8. ruby-on-rails - Rails 基本 Base64 身份验证 - 2

    我正在尝试复制此GETcurl请求:curl-D--XGET-H"Authorization:BasicdGVzdEB0YXByZXNlYXJjaC5jb206NGMzMTg2Mjg4YWUyM2ZkOTY2MWNiNWRmY2NlMTkzMGU="-H"Content-Type:application/json"http://staging.example.com/api/v1/campaigns在Ruby中,通过电子邮件+apikey生成身份验证:auth="Basic"+Base64::encode64("test@example.com:4c3186288ae23fd9661c

  9. arrays - 在一行中选择数组的第一个和最后一个元素 - 2

    我的任务是从数组中选择最高和最低的数字。我想我很清楚我想做什么,但只是努力以正确的格式访问信息以满足通过标准。defhigh_and_low(numbers)array=numbers.split("").map!{|x|x.to_i}array.sort!{|a,b|ba}putsarray[0,-1]end数字可能看起来像"80917234100",要通过,我需要输出"9234"。我正在尝试putsarray.first.last,但一直无法弄明白。 最佳答案 有Array#minmax完全满足您需要的方法:array=[80,

  10. ruby-on-rails - 在 rails 中显示 base64 编码的图像 - 2

    我正在向我的Controller发送一个base64图像并按原样保存它。现在我需要显示该图像。这是我要显示的内容,但未显示图像:"/>为了编码,我使用了这个java脚本函数encodeURIComponent();我的编码图像格式:data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/........ 最佳答案 你不需要解码base64应该可以 关于ruby-on-rails-在rails中显示base64编码的图像,我们在StackOve

随机推荐