gpt4 book ai didi

ios - 行返回类型警告的 TableView 高度

转载 作者:行者123 更新时间:2023-11-28 18:20:51 30 4
gpt4 key购买 nike

在 iPad Retina 64 位模拟器上运行 Xcode 5.1(7.1 测试版)时,我需要将返回类型更改为“ double ”,而在具有 7.1 测试版的设备上我必须将其更改为“ float ”。如果我在不更改类型的情况下运行该应用程序,则单元格高度实际上为 0。其他人之前是否遇到过或遇到过此问题?我在网上找不到任何关于它的信息。

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([lastSelectedIndexPath isEqual:indexPath]) {
return 310.0;
} else {
return 120.0;
}
}

Compiler warning

最佳答案

你所要做的就是替换方法行

-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//^^^^^ The return type is incorrect, the whole line needs to be replaced

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

这是因为 Apple 的 heightForRowAtindexPath 默认委托(delegate)方法需要使用 CGFloat 而不是 float。您还可以通过进入 .h 文件并右键单击 UITableViewDelegate 或 UITableViewDataSource 协议(protocol)来仔细检查您可能会实现的 future 委托(delegate)方法,以查看 Apple 的完整方法构造列表以及它们应该如何被调用、使用以及它们的返回类型是什么.

有关使用 CGFloat 而不是 float 以响应 Wain 的评论的更多信息。来自帖子Why to use CGFloat instead of float

“CGFloat 只是 float 的类型定义。这为 CGFloat 提供了灵 active ,使其在未来变得与众不同。这就是为什么使用它可以使您的代码面向 future 。Objective-C 对许多类型都这样做,NSInteger 是另一个例子。” - Jason McReary。

因此 Apple 喜欢使用这些 type-def 并鼓励开发人员也这样做,这样您的代码就可以成为 future 的证明,以防底层架构在如何处理 float 方面发生变化。

关于ios - 行返回类型警告的 TableView 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20975645/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com