开发者

UITableView with an array of arrays and dictionaries

开发者 https://www.devze.com 2023-03-08 02:23 出处:网络
I have question regarding UITableView - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

I have question regarding UITableView

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

I have no problem to put the data into the tableView with an array of dictionaries:

dictionary = [allData objectAtIndex:indexPath.row]; 

But how can I do the same if allData array in this case contains arrays with dictionaries?

I have an UISegmentedControl where each segment repres开发者_如何学Goents an webservice request except the first segment which requests all requests. All the results from the first segment is then collected in an Array. So this contains an array for each requests, with dictionaries. The result from any other request is in an array with dictionaries.

Thanks,


If I understand correctly, each cell is represented by a dictionary containing its attributes. Each section is represented by an array of those dictionaries. Now you just need another array containing the section arrays.

    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];
        ...
   }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号