带标题的UITableView:发送到实例的无法识别的选择器

时间:2014-08-08 20:43:25

标签: ios objective-c uitableview

尝试使用节标题设置UITableView,并在运行编译器并尝试导航到屏幕时出现此错误:

  

[UIView tableView:numberOfRowsInSection:]:无法识别的选择器发送到实例0x7fac00fadce0

问题出现在选择器@"数据"?还需要做些什么才能让它得到认可?

这里是.h

@interface InviteContactsViewController : UIViewController <ABPeoplePickerNavigationControllerDelegate> {
    IBOutlet UITableView *mainTable;
    NSMutableArray *dataArray;
}

和.m

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

    dataArray = [[NSMutableArray alloc] init];

    NSArray *firstItemsArray = [[NSArray alloc] initWithObjects:@"Item 1", @"Item 2", @"Item 3", nil];
    NSDictionary *firstItemsArrayDict = [NSDictionary dictionaryWithObject:firstItemsArray forKey:@"data"];
    [dataArray addObject:firstItemsArrayDict];

    NSArray *secondItemsArray = [[NSArray alloc] initWithObjects:@"Item 4", @"Item 5", @"Item 6", @"Last Item", nil];
    NSDictionary *secondItemsArrayDict = [NSDictionary dictionaryWithObject:secondItemsArray forKey:@"data"];
    [dataArray addObject:secondItemsArrayDict];
}

// Tell table view how many sections it can expect to receive
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [dataArray count];
}

// Tell table view how many rows in each section to expect
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    // Number of rows it should expect should be based on the section
    NSDictionary *dictionary = [dataArray objectAtIndex:section];
    NSArray *array = [dictionary objectForKey:@"data"];
    return [array count];
}

// Specify section headers
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    if(section == 0)
        return @"Section 1";
    if(section == 1)
        return @"Section 2";
    else {
        return @"nothing here";
    }
}

0 个答案:

没有答案