0

当我构建并运行时,没有显示任何内容。没有文字只是空单元格。

这是我的代码:

#import "plungerselection.h"

@implementation plungerselection
@synthesize tableData;

-(void) viewDidLoad
{
    tableData = [[NSArray alloc] initWithObjects:@"Turbo", @"Hollow Turbo", @"Single Pad", @"Dual Pad", @"Bullet", nil];
    [super viewDidLoad];
}


#pragma mark - TableView Data Source Methods 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;{

    return [tableData count];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    UITableViewCell *cell = nil;

    cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];

        cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    }

    return cell;

}
@end
4

2 回答 2

0

确保您已在 Interface Builder 中连接数据源和委托连接。

于 2012-07-30T19:27:41.343 回答
0

dequeueReusableCellWithIdentifier:如果在这种情况下没有发生返回,则您只是在单元格中设置文本nil(即使它发生了,也只会在所有需要的单元格进入队列之前发生几次)。您应该将文本设置在if (cell == nil)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    UITableViewCell *cell = nil;

    cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];
    }

    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];

    return cell;

}
于 2012-07-30T19:31:36.633 回答