Reading plist into TableView

后端 未结 2 1626
轮回少年
轮回少年 2021-02-11 10:37

I started this project with a simple plist of a dictionary with two arrays of strings. I now want to add more information and want to use this plist structure:

R         


        
2条回答
  •  星月不相逢
    2021-02-11 11:18

    First, do not use -[UITableViewCell initWithFrame:reuseIdentifier:]. It has been deprecated and will give you a warning, plus it will make your subtitle harder to implement. This code is a modified version of yours which loads the information, sets the title to the Color property, and sets the subtitle to a string containing the Rvalue, Gvalue, and Bvalue properties.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        NSUInteger section = [indexPath section];
        NSUInteger row = [indexPath row];
        NSString *key = [keys objectAtIndex:section];
        NSArray *colorSection = [colors objectForKey:key];
    
        static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier];
    
        if(cell == nil) {
            cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier: SectionsTableIdentifier] autorelease];
        }
    
        NSDictionary *color = [colorSection objectAtIndex:row];
        cell.textLabel.text = [color objectForKey:@"Color"];
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@, %@",[color objectForKey:@"Rvalue"],[color objectForKey:@"Gvalue"],[color objectForKey:@"Bvalue"]];
        [cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton]; //add disclosure button to rows
        return cell;
    }
    

提交回复
热议问题