【发布时间】:2017-11-03 19:39:02
【问题描述】:
我是 IOS 新手,我正在尝试在 UITableView 中制作多个原型单元格,但我总是得到相同大小的行,不知道为什么会这样。我已经搜索了很多!但没有线索,任何帮助对我来说都会很棒。提前致谢。This is the image for what I am doing 和 this is what I am getting as output。
这是我的 DataSource 方法的代码......
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section
{
return 12;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger count = indexPath.row;
if(count == 0)
{
DetailPostCell *Cell1 = (DetailPostCell *)[tableView
dequeueReusableCellWithIdentifier:@"Cell1"
forIndexPath:indexPath];
return Cell1;
}
else
{
CommentCell *Cell2 = (CommentCell *)[tableView
dequeueReusableCellWithIdentifier:@"Cell2"
forIndexPath:indexPath];
return Cell2;
}
}
【问题讨论】:
-
请注意,任何instoryboard 的大小都没有任何意义:它只是您工作时间的一个指标。关于表格视图和单元格,您可能需要了解 tableView#heightForRowAt,享受!
-
@Fattie 你的意思是说我必须重写这个方法并为每一行指定高度?
-
当然,我会指导您阅读有关表格视图的任何教程。假设您有两种“类型”的行(假设一种是图像,一种是文本消息)。所以,这是完全正常的:在调用 tableView#heightForRowAt 时,您基本上会说“如果图像,返回 190,如果消息返回 75” - 或其他任何内容
-
为了清楚起见,在当今所有现实世界的 iOS 工程中,您都使用自动布局。但是为了让您开始学习曲线,请继续尝试 tableView#heightForRowAt - 享受
-
等等——你在用objectiveC吗?!你真的在浪费你的时间。只需单击即可在 Swift 中开始一个新项目,并享受您的学习体验! “ray wenderlich”教程对于爱好者来说是一个不错的起点,尽情享受吧! tableView#heightForRowAt
标签: ios objective-c uitableview storyboard row-height