2012-07-30 63 views
0

当我建立并运行时没有任何显示。没有文字只是空单元格。UITableView加载但没有显示

这里是我的代码:

#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 

回答

0

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

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; 

} 
相关问题