索引 0 大小的 UITableView 单元格

发布于 2025-01-06 00:54:13 字数 207 浏览 3 评论 0原文

自定义表格中第一个单元格以像 Netflix 应用程序一样显示(即更大/不同)的最佳方法是什么?为了以后使用方便,已经要求我尽量使用IB,方便以后的编辑。

这是 Netflix 桌子的照片。 http://cl.ly/3j1d473d1j160502160t

What is the best way to customize the first cell in a table to display like the Netflix application (i.e. bigger/different)? For ease of future use, I have been asked to use IB as much as possible to make it easier for future editing.

Here is a photo of the Netflix table. http://cl.ly/3j1d473d1j160502160t

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

念﹏祤嫣 2025-01-13 00:54:13

使用表头视图。将视图拖到表视图的顶部,它将成为“表头视图”。

如果您有其他这样的基本上恒定的“单元格”(并且可能会打开/关闭),您可以考虑将 UITableViewCell 对象放入 xib 中,并从 tableView:cellForRowAtIndexPath 返回它们:委托方法。还要实现 tableView:heightForRowAtIndexPath: 方法。

两者可以具有相同的总体轮廓,例如:

-(UITableViewCell*)tableView:(UITableView*)tv cellForRowAtIndexPath:(NSIndexPath*)ip
{
    if ( ip.section==0 ) return headerCell;
    // ...handle regular cells
}

-(CGFloat)tableView:(UITableView*)tv heightForRowAtIndexPath:(NSIndexPath*)ip
{
    if ( ip.section==0 ) return headerCell.frame.size.height;
    // ...handle regular cells
    return 44;
}

Use the table header view. Drag a view to the top of the table view and it will become the "table header view".

If you have other such "cells" which are essentially constant (and might be switched on/off) you can consider putting UITableViewCell objects in your xib, and returning them from the tableView:cellForRowAtIndexPath: delegate method. Also implement the tableView:heightForRowAtIndexPath: method.

Both can have the same general outline, like:

-(UITableViewCell*)tableView:(UITableView*)tv cellForRowAtIndexPath:(NSIndexPath*)ip
{
    if ( ip.section==0 ) return headerCell;
    // ...handle regular cells
}

-(CGFloat)tableView:(UITableView*)tv heightForRowAtIndexPath:(NSIndexPath*)ip
{
    if ( ip.section==0 ) return headerCell.frame.size.height;
    // ...handle regular cells
    return 44;
}
温柔女人霸气范 2025-01-13 00:54:13

要么使其不是单元格(如表格的标题视图),要么实现 -[UITableViewDelegate tableView:heightForRowAtIndexPath:] 返回不同的高度。您可以使用 IB 来安装表头,但解决此问题的更复杂方法将需要使用代码。

Either make it something that isn't a cell (like the table's header view), or implement -[UITableViewDelegate tableView:heightForRowAtIndexPath:] to return a different height. You can use IB to install a table header, but more complex ways of attacking this problem will require working in code.

箜明 2025-01-13 00:54:13

这是您可以使用的片段。它是表的标题视图...

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

 if(section==0){ UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableview.frame.size.width, 44)];
[view setBackgroundColor:[UIColor redColor]]; UILabel
*label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)]; 
[label setText:@"Hello!!"];
[label setBackgroundColor:[UIColor clearColor]]; 
[view addSubview:label]; return view; 
 }return nil;

}
在这里您可以设置 tableViewHeaderSection 的高度。

  • (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)部分{

    返回100;
    (CGFloat )

Here is a snippet that you can use.It is table's header view...

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

 if(section==0){ UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableview.frame.size.width, 44)];
[view setBackgroundColor:[UIColor redColor]]; UILabel
*label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)]; 
[label setText:@"Hello!!"];
[label setBackgroundColor:[UIColor clearColor]]; 
[view addSubview:label]; return view; 
 }return nil;

}
Here You can set the height for the tableViewHeaderSection.

  • (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return 100;
    }

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文