数据是类似这样的。但是在plist文件中。
A =     (
        aa,
        a1,
        a2,
        a3,
        a4
    );
    B =     (
        b1,
        b2,
        b3,
        b4,
        b5
    );
    C =     (
        c1,
        c2,
        c3,
        c4,
        c5
    );
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger section = [indexPath section];
    NSUInteger row = [indexPath row];
    
    NSString *key = [keys objectAtIndex:section];
  
    NSArray *nameSection = [names objectForKey:key];
    NSLog(@"Name Section is : %@",nameSection);
    NSLog(@"key Section is : %@",key);
    
    static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SectionsTableIdentifier] autorelease];
    }
    
    cell.textLabel.text = [nameSection objectAtIndex:row];//这名报错是什么原因?我在公司用Xcode3写没事,回家用xcode4写就报表,很郁闷,
    return cell;
}难道和版本有关系?写法不一样?求解。

解决方案 »

  1.   

    加载数据:- (void)viewDidLoad
    {
        [super viewDidLoad];
        NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"];
        NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
        self.names = dict;
       
        [dict release];
        
        NSArray *array = [[names allKeys] sortedArrayUsingSelector:@selector(compare:)];
        self.keys = array;
    }
      

  2.   

    NSArray *nameSection = [names objectForKey:key]; 需要先retain, 用完后释放