2011-05-22 32 views
0

我有一个关于问题的UITableView的数组的UITableView与数组和字典

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

我没有问题,把数据放入的tableView使用词典的数组:

dictionary = [allData objectAtIndex:indexPath.row]; 

却怎么也我这样做,如果allData数组在这种情况下包含字典的数组?

我有一个UISegmentedControl其中每个段代表一个Web服务请求,除了请求所有请求的第一个段。 然后将第一部分的所有结果收集到一个数组中。因此,这包含每个请求的数组和字典。 任何其他请求的结果都在包含字典的数组中。

谢谢,

+0

我想有一个部分显示内部数组的所有结果。 – Silversnail 2011-05-22 21:17:46

回答

2

如果我正确理解,每个单元由包含其属性的辞典来表示。每个部分都由这些字典的数组表示。现在您只需要另一个包含节数组的数组。

NSMutableArray *allData;    // just one 
    NSMutableArray *sectionArray;   // one per section 
    NSMutableDictionary *cellDictionary; // one per row 
    ... 

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
     return [allData count]; 
    } 

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  { 
     return [[allData objectAtIndex:indexPath.section] count]; 
    } 

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
     NSDictionary *dictionary = [allData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; 
     ... 
    }