2014-10-30 64 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 2014-10-30 22:37:45

+0

錯誤在哪裏? – 2014-10-30 22:44:57

回答

1

您正在聲明viewDidLoad方法內的方法。 Objective-C不支持方法嵌套。相應地修復您的整個代碼格式並添加缺少的}。

+0

謝謝安迪! – Purp 2014-10-31 00:56:30