简体   繁体   English

动态静态表视图

[英]Dynamic static table view

Ok, so there is "static cells" content mode for creating settings-like views. 好的,因此存在用于创建类似设置的视图的“静态单元格”内容模式。 Can anyone suggest how to deal with that if you have different number of settings to be displayed in different circumstances? 如果在不同情况下要显示的设置数量不同,谁能建议如何处理? ie in one case I have three cells: two cells with switches and one with button, and in other case - just last cell with button. 也就是说,在一种情况下,我有三个单元格:两个带有开关的单元格,一个带有按钮的单元格,在另一种情况下,-最后一个带有按钮的单元格。

Should I switch back to dynamic cells? 我应该切换回动态单元格吗? How should I handle headers' behavior in this case? 在这种情况下,我应该如何处理标题的行为? Thanks 谢谢

I think you better use dynamic cells. 我认为您最好使用动态单元格。 for header and footer of cells and sections you can just call this methods: 对于单元格和节的页眉和页脚,您可以调用以下方法:

- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section  
{  
    return @"This will be the header!!!!";  
}

or 要么

- (NSString *) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section  
{  
    return @"This will be the footer!!!!";  
}

PS there were some methods, something like "viewForHeaderInSection" and "viewForFooterInSecton" . PS有一些方法,例如"viewForHeaderInSection""viewForFooterInSecton" But I don't remembre the complete implementation. 但是我不建议完整的实现。

PS^2. PS ^ 2。 you have to set the Table View Style to Grouped! 您必须将“表格视图样式”设置为“分组”! See this image for a tiny help 看到这个图像有一点帮助

Static cells and a simple if in your implementation of numberOfRowsInSection: and cellForRowAtIndexPath to return your 3 static cells or just the last one depending on your condition. 静态单元格和简单的if在实现numberOfRowsInSection:cellForRowAtIndexPath实现中),则根据您的条件返回3个静态单元格或仅返回最后一个静态单元格。 Simple enough. 很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM