回答
您可以创建一个结构类似这样的
[
{
"Title": "Section 1",
"Rows": [
{
"Title": "Row 1",
"Rows": [
{
"Title": "Sub Row 1",
"Rows":[]
}
]
}
]
}
]
这是字典的数组。每个部分都有一个行数组,每行都有一个数组。
你能解释更多吗? – DungProton 2013-05-03 13:06:35
@DungProton我会为你制定一个演示代码。 – Anupdas 2013-05-03 13:08:03
@DungProton我把我的答案放在演示源代码。它只是显示你如何显示这样的数据。您可以制定如何向每个部分添加新行的代码。 – Anupdas 2013-05-03 13:49:43
您可以使用分组tableview
为,但它不会给你的iPhone全行的宽度就像在你的图片。
如果你使用普通的tableview,它应该给你全行的外观,但添加加号按钮可能会变得困难。
你需要有一个来源可以说每个部分行
对于图像使用cell.imageView.image= yourimage;
对于箭头数组或字典使用cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
对于(10),你需要要么使用cell.accessoryView= yourcustomview
//create multiple section according to your picture it is 2
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//return an integer here from a source,variable or just return static int
return 2;
}
//add plus button for each section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
// Create header view and add label as a subview
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 400, 320, 400)];
//add a button to open edit
UIButton *declineButton=[UIButton buttonWithType:UIButtonTypeCustom];
[declineButton setTag:section];
declineButton.titleLabel.tag=1;
[declineButton setFrame:CGRectMake(450,50,70,40)];
[declineButton setTitle:@"Edit" forState:UIControlStateNormal];
UIImage *declinebuttonImage = [[UIImage imageNamed:@"[email protected]"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 20, 20, 20)];
[declineButton setBackgroundImage:declinebuttonImage forState:UIControlStateNormal];
[declineButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[declineButton addTarget:self action:@selector(declineEvent:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:declineButton];
return view;
}
- (IBAction)declineEvent:(id)sender {
UIButton *button = (UIButton *)sender;
NSInteger row = button.tag;
NSInteger column = button.titleLabel.tag;
//NSIndexPath *selectedSection= [NSIndexPath indexPathForRow:column inSection:row];
NSLog(@"Row is %i column is %i",row,column);
//populate your source array for the section according to your needs here
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return yoursourceforthissection;
}
我认为你应该使用自定义表格视图单元格有一个表v IEW。
http://www.appcoda.com/customize-table-view-cells-for-uitableview/
检查这个希望这会帮助你。
我有一个类似的项目,这在Github上。 基本上它是一个可扩展的部分UITableView。 以下步骤使其成为我工作:
NSMutableDictionary
为dataSource
,该字典包含NSMutableArrays
作为每一行的键值。- 您将有另一个
NSMutableArray
与您的NSMutableDictionary
大小相同。此NSMutableArray
包含BOOL
值,YES
代表展开的部分,NO
代表折叠部分。在我的案例中,默认情况下所有部分都是折叠的。 3.您的tableView中的部分数量是您的NSMutableDictionary
的大小。 - 如果您的
NSMutableArray
的Bool
值在某个索引路径中包含YES
,则此部分的行数是您从NSMutableDictionary
获取的索引路径值的数组大小。否则,你将只有1行此部分。
例子:
if ([[boolArray objectAtIndex:section] boolValue]) {
return [[yourDict valueForKey:yourKeyForIndexPAth] count];
}else{
return 1;
}
刚检查出来UND随意使用的代码:
- 1. SQLAlchemy自定义类型包含多列
- 2. 如何在自定义docletpath中包含多个路径?
- 3. 删除包含多个单词的行
- 4. 结果包含多个行错误mysql
- 5. 一个类应该包含多少行?
- 6. 包含新行的Csv文件(多行)
- 7. 在一个自定义的UIViewController包含一个UITableView子视图
- 8. 如何将包含多个列的结果分为两行,每行为
- 9. 自定义包含templatetag render_model
- 10. ember.js包含自定义js
- 11. 如何在包含多个根节点时包含biml文件?
- 12. 如何包含自定义SQL函数
- 13. 如何包含自定义C库
- 14. 定义包含“
- 15. 如何从命令行运行包含多个类和包的java程序?
- 16. Android AutoCompleteTextView自定义列表项包含多个视图
- 17. 不含定义为“包含”
- 18. 如何执行自包含耙构建?
- 19. 标量子查询包含多行
- 20. 返回多行包含列表
- 21. queryString包含多行阿拉伯文本
- 22. Ansible:包含管道的多行变量
- 23. 元素可以包含多少行
- 24. 如何为List.filter包含多个参数?
- 25. 如何包含同名多个元素
- 26. SQL多个包含连接
- 27. XPATH:包含多个文本
- 28. jquery包含多个值
- 29. ASP.NETSequence包含多个元素
- 30. InputStream包含多个文件
为了使问题清晰。你也有章节礼节,一节有很多行,每行都有正确的子行。可以添加一行,同样可以添加一个子行,我是否正确? – Anupdas 2013-05-03 12:59:24
是的,这是正确的 – DungProton 2013-05-03 13:00:50