在我的头文件中:
@interface HTMLClassesViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
所以我确实声明了dataSource
and delegate
。
在我的实现文件中:
- (void)viewDidLoad {
[super viewDidLoad];
if (self.arrayOfClasses == nil) {
self.arrayOfClasses = [[NSMutableArray alloc] init];
}
NSMutableArray *array = [[NSMutableArray alloc] init];
... // Gather data from HTML source and parse it into "array"
self.arrayOfClasses = array; //arrayOfClasses here is non-nil (with correct objects)
NSLog(@"%@ test1", [self.arrayOfClasses objectAtIndex:0]);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"%@ test1.5", [self.arrayOfClasses objectAtIndex:0]);
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"%@ test2", [self.arrayOfClasses objectAtIndex:0]);
return [self.arrayOfClasses count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"%@ test3", [self.arrayOfClasses objectAtIndex:0]);
static NSString *CellIdentifier = @"WebCollegeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [self.arrayOfClasses objectAtIndex:indexPath.row];
return cell;
}
这是来自的输出NSLog
:
2012-11-24 22:52:19.125 ArizonaCollegeSearch[72404:c07] CSE 240 test1
2012-11-24 22:52:19.126 ArizonaCollegeSearch[72404:c07] CSE 240 test1.5
2012-11-24 22:52:19.127 ArizonaCollegeSearch[72404:c07] (null) test1.5
2012-11-24 22:52:19.127 ArizonaCollegeSearch[72404:c07] (null) test2
正如你所看到的,numberOfSectionsInTableView
被一个非空对象调用,然后被一个空对象numberOfRowsInSection
调用,被一个空对象调用,并且cellForRowAtIndexPath
根本没有被调用。我什至没有[self.tableView reloadData]
地方。
有什么建议么?