2012-03-10 61 views
1

我試圖用initWithStyle運行下面的代碼:UITableViewCellStyleSubtitle但沒有顯示字幕。你能告訴我什麼是錯的嗎?initWithStyle:UITableViewCellStyleSubtitle但字幕沒有顯示

在此先感謝!

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 
@synthesize listData; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    NSArray *array = [[NSArray alloc] initWithObjects:@"Sleepy", @"Sneezy", @"Bashful", @"Happy", @"Doc", @"Grumpy", @"Dopey", @"Thorin", @"Dorin", @"Nori", @"Ori", @"Balin", @"Dwalin", @"Fili", @"Kili", @"Oin", @"Gloin", @"Bifur", @"Bofur", @"Bombur", nil]; 
    self.listData = array; 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    self.listData = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

#pragma mark - 
#pragma mark Table View Data Source Methods 
- (NSInteger)tableView:(UITableView *)tableView 
    numberOfRowsInSection:(NSInteger)section 
{ 
    return [self.listData count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] 
       initWithStyle:UITableViewCellStyleSubtitle 
       reuseIdentifier:SimpleTableIdentifier]; 
    } 

    UIImage *image = [UIImage imageNamed:@"star.png"]; 
    cell.imageView.image = image; 

    NSUInteger row = [indexPath row]; 
    cell.textLabel.text = [listData objectAtIndex:row]; 
    return cell; 

    if (row < 7) 
     cell.detailTextLabel.text = @"Mr. Disney"; 
    else 
     cell.detailTextLabel.text = @"Mr.Tolkien"; 
} 

@end 

回答

0
return cell; 

應該是最後一道防線。它在設置detailTextLabeltext屬性之前返回。

另外,您應該從Xcode收到關於「無法訪問的代碼」的警告。

+0

這樣做。謝謝! – pdenlinger 2012-03-10 17:18:47