【问题标题】:Objective-C use of undeclared identifier 'numberOfSectionsInTableView'Objective-C 使用未声明的标识符“numberOfSectionsInTableView”
【发布时间】:2014-10-30 22:35:44
【问题描述】:

不知道我哪里出错了。我的理解是导入 UIKit 将启用 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

【问题讨论】:

    标签: objective-c undeclared-identifier


    【解决方案1】:

    您在 viewDidLoad 方法中声明您的方法。 Objective-C 不支持方法嵌套。用它的格式修复你的整个代码,并相应地添加缺少的 }。

    【讨论】:

      猜你喜欢
      • 2014-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-21
      • 1970-01-01
      • 1970-01-01
      • 2012-07-12
      相关资源
      最近更新 更多