回答
您可以創建一個結構類似這樣的
[
{
"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