2013-05-05 32 views
0

我想建立一个UITableView只是像这样的(请注意在截图灰色细胞(S,T,W)): enter image description here如何在UITableView中创建“标题”单元格?

。 这是两个自定义单元吗?或者还有其他小费?

+1

我可以建议你通过表视图编程指南(https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/AboutTableViewsiPhone/AboutTableViewsiPhone.html#阅读// apple_ref/DOC/UID/TP40007451)。如果你要使用表格,这是一个必须阅读的文档。它涵盖了像这样的事情以及使用表格的许多其他方面。 – rmaddy 2013-05-05 23:11:47

回答

1

这是标准样式的UITableView的“标题”。

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 

    if (section == 20) return @"S"; 

    if (section == 21) return @"T"; 

    if (section == 22) return @"W"; 

    return @"Undefined"; 
} 
+0

它在上面回答我的问题Wain答案如此。我必须将我的UITableView分成几部分。非常感谢你。 – androniennn 2013-05-05 22:08:14

+2

仅供参考 - 这是设置一组按字母顺序排列的标题的可怕方法。使用'UILocalizedIndexedCollat​​ion'是节标题和索引的更好方法。至少,使用一系列标题。或者至少使用'switch'语句而不是一整套'if'语句。 – rmaddy 2013-05-05 23:13:30

+0

@rmaddy当然,我没有显示正确的实现来设置按字母顺序的标题。只是参考OP问题的一些快速示例代码给他一个想法。 – 2013-05-06 02:04:26

1

这些行是节标题。见titleForHeaderInSectionhere

+0

因此,如果我有2个部分,我会有2个标题?我想过一个自定义单元格,如果我有一个部分,我可以创建多个标题。感谢您的回答,现在我知道如何做到这一点。 – androniennn 2013-05-05 22:07:12

相关问题