2014-10-30 3 views
-4

Не знаете, где я ошибся. Я понимаю, что импорт UIKit позволит использовать метод numberOfSectionsInTableView ... Любая помощь приветствуется.Objective-C использование незаявленного идентификатора 'numberOfSectionsInTableView'

//HEADER 

#import <UIKit/UIKit.h> 

@interface MainScrollingTableVC : UITableViewController <UITableViewDelegate, UITableViewDataSource> { 
    int selectedIndex; 
    NSMutableArray *titleArray; 
    NSArray *subtitleArray; 
    NSArray *textArray; 
} 

@end 

//IMPLEMENTATION 

#import "MainScrollingTableVC.h" 
#import "MainExpandingCellTableViewCell.h" 

@interface MainScrollingTableVC() 

@property (strong, nonatomic) IBOutlet UITableView *tableView; 

@end 

@implementation MainScrollingTableVC 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.tableView.delegate = self; 
    self.tableView.dataSource = self; 

    //index = -1 means no cell is expanded or should expand 
    selectedIndex = -1; 

    titleArray = [[NSMutableArray alloc] init]; 
    NSString *string; 

    //create consecutive array of 8 numbers. 1...2...etc... 
    for(int ii = 1; ii <= 8; ii++) { 
     string = [[NSString alloc] initWithFormat:@"Row %i", ii]; 
     [titleArray addObject:string]; 

    } 

    subtitleArray = [[NSArray alloc] initWithObjects:@"First row", @"Second row", @"Third row", @"Fourth row", @"Fifth row", @"Sixth row", @"Seventh row", @"Eigth row", nil]; 

    textArray = [[NSArray alloc] initWithObjects:@"Apple", @"Orange", @"Grape", @"Banana", @"Kiwi", @"Blueberry", @"Apricot", @"Lemon", nil]; 

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
     return 1; 
    } 

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
     return titleArray.count; 
    } 

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
     static NSString *cellIdentifier = @"MainExpandingCell"; 
     MainExpandingCell *cell = (MainExpandingCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
     if(cell == nil) { 
      NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MainExpandingCell" owner:self options:nil]; 
      cell = [nib objectAtIndex:0]; 
     } 
     if(selectedIndex == indexPath.row) { 
      //Do expanded cell stuff 
     } else { 
      //Do closed cell stuff 
     } 

     cell.titleLabel.text = [titleArray objectAtIndex:indexPath.row]; 
     cell.timeLabel.text = [subtitleArray objectAtIndex: indexPath.row]; //CHECK VARS 
     cell.textLabel.text = [textArray objectAtIndex:indexPath.row]; 
     int etaLabel = (indexPath.row + 1) * 25; 
     cell.etaLabel.text = [NSString stringWithFormat:@"%i", eta] 
     cell.clipsToBounds = YES; 

     return cell; 
    } 

} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 
+0

Отсортировать код – Fogmeister

+0

где ошибка? –

ответ

1

Вы объявляете свои методы в методе viewDidLoad. Objective-C не поддерживает вложенность метода. Исправьте весь код с его форматированием и добавьте недостающие} соответственно.

+0

Спасибо Энди! – Purp

Смежные вопросы