2016-09-29 71 views
0

我在Array內有三個字典,名爲_searchArray。在tableview中,我想顯示這個數組。有時這個數組可以包含一個或兩個或三個字典。Tableview基於Array結果顯示數據?

{ 
    "chat_contacts" = {}, 
    "other_contacts" = {}, 
    "messagesContacts" = {} 
} 

的TableView:

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { 
    return _searchArray.count; 
} 


-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {  
     if(section == 0){ 
      return [[_searchArray objectForKey:@"chatContacts"] count]; 
     } 

     if(section == 1) { 
      return [[_searchArray objectForKey:@"otherContacts"] count]; 
     } 

     if(section == 2) { 
      return [[[_searchArray objectForKey:@"messagesContacts"] objectForKey:@"messages"]count]; 
     } 
} 

假設如果數組不包含other_contacts,messages_contacts具有第1

返回如果數組不包含chat_contacts和other_contacts,messages_contacts必須在第0部分返回。

如何顯示正確的數據?

+0

部分的正確計數您可以檢查'viewForheader'委託方法計數,如果數組爲空則只是返回視圖' 0'高度視圖將不會顯示在'tableview'上,對於'cellForRow'你可以做到這一點。 –

+0

我想你沒有得到我的問題。我想顯示基於數據的結果。如果數組能夠3字典,它將顯示在命令中。但任何東西都缺少如何添加下一個字典在丟失字典的地方? – Balasubramanian

回答

0

你需要做的第一件事就是返回

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;