2011-12-18 46 views
0

在配置數組中的表格單元格時遇到了一些麻煩。已註釋掉LLVM編譯器返回的錯誤。小區配置方法

實現文件:

#import "BIDFirstLevelController.h" 
#import "BIDSecondLevelViewController.h" 

@implementation BIDFirstLevelController 

@synthesize controllers; 

- (void) viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.title = @"First Level"; 
    NSMutableArray *array = [[NSMutableArray alloc]init]; 
    self.controllers = array; 
} 

- (void) viewDidUnload 
{ 
    [super viewDidUnload]; 
    self.controllers = nil; 
} 

#pragma mark - 
#pragma mark Table Data Source Methods 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [self.controllers count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *FirstLevelCell = @"FirstLevelCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FirstLevelCell]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] 
       initWithStyle:UITableViewCellStyleDefault reuseIdentifier:FirstLevelCell]; 
    } 
} 


// Configure the cell 
NSUInteger row = [indexPath row]; // replace with NSUIndexPath 
BIDSecondLevelViewController *controller = [controllers objectAtIndex:row]; //replace controllers with controller 
cell.textLabel.text = controller.title; // unknown type name 'cell', Expected identifier or '(' 
cell.imageView.image = controller.rowImage; // Expected identifier or '(
cell.accessoryType = UITableViewAccessoryDisclosureIndicator; // Unknown type name 'cell' 
return cell; 
    } 

#pragma mark - 
#pragma mark Table View Delegate Methods 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{NSUInteger row = [indexPath row]; 
    BIDSecondLevelViewController *nextController = [self.controllers objectAtIndex:row]; 
    [self.navigationController pushViewController:nextController animated:YES]; 


@end 

接口文件:

#import <UIKit/UIKit.h> 

@interface BIDFirstLevelController : UITableViewController 

@property (strong, nonatomic) NSArray *controllers; 

@end // Unexpected '@' in program 

回答

0

你需要你的if語句,你tableView:cellForRowAtIndexPath:後刪除一個大括號應該是這樣的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *FirstLevelCell = @"FirstLevelCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FirstLevelCell]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] 
       initWithStyle:UITableViewCellStyleDefault reuseIdentifier:FirstLevelCell]; 
    } 
    // DELETE THE } THAT IS HERE 
    // Configure the cell 
    NSUInteger row = [indexPath row]; 
    BIDSecondLevelViewController *controller = [controllers objectAtIndex:row]; 
    cell.textLabel.text = controller.title; 
    cell.imageView.image = controller.rowImage; 
    cell.accessoryType = UITableViewAccessoryDisclosureIndicator; 
    return cell; 
} 

你還需要添加花括號來關閉您的最終功能:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    NSUInteger row = [indexPath row]; 
    BIDSecondLevelViewController *nextController = [self.controllers objectAtIndex:row]; 
    [self.navigationController pushViewController:nextController animated:YES]; 
} // This curly brace is missing 
@end