2012-07-30 29 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; 

} 
相關問題