未填充UITableView,因为从不调用tableView:cellForRowAtIndexPath

时间:2012-07-05 13:03:01

标签: objective-c ios

我的UITableView未填充,因为:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
永远不会调用

这是我初始化表格的方式:

self.recentScannedItems = [[[UITableView alloc] initWithFrame:kLastScannedPortrait style:UITableViewStylePlain] autorelease];
    [self.recentScannedItems setDelegate:self];
    [self.recentScannedItems setDataSource:self];
    [self.view addSubview:recentScannedItems];

我错过了什么?

2 个答案:

答案 0 :(得分:0)

您的班级是否符合UITableViewDataSource的要求?像:

@interface mySuperClass : UIViewController <UITableViewDataSource, UITableViewDelegate>

答案 1 :(得分:0)

您是否正确实施了数据源方法:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView {
    // Return the number of sections.
    return NumberOfSections;
}

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.

    return NumberOfRows;
}

如果您没有实现此方法,或者如果您在其中返回0,则不会调用cellForRowAtIndexPath