2012-04-07 142 views
0

我有以下代码向我显示一个自定义列表与图像和一些文本旁边,但我看不到我的列表填充给出的五个示例数据。有人能帮我吗???自定义UITableView不显示

#import "RestListViewController.h" 
#import "RestListCustomTableCell.h" 

@implementation RestListViewController 

/* 
// The designated initializer. Override to perform setup that is required before the view is loaded. 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
     if (self) { 
     // Custom initialization 
} 
return self; 
} 
*/ 

/* 
// Implement loadView to create a view hierarchy programmatically, without using a nib. 
- (void)loadView { 
} 
*/ 


    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
    - (void)viewDidLoad { 
[super viewDidLoad]; 
    } 
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:      (NSIndexPath  *)indexPath { 
    //NEVER REACHES HERE!!!!!!!!!! 
NSLog(@"BUILD THE TABLE!!!"); 
static NSString *CellIdentifier = @"Cell"; 
RestListCustomTableCell *cell = (RestListCustomTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[RestListCustomTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Set up the cell… 

switch (indexPath.row) { 

    case 0: 
     cell.primaryLabel.text = @"Meeting on iPhone Development"; 
     cell.secondaryLabel.text = @"Sat 10:30"; 
     cell.myImageView.image = [UIImage imageNamed:@"restabapiknik.png"]; 
     break; 
    case 1: 
     cell.primaryLabel.text = @"Call With Client"; 
     cell.secondaryLabel.text = @"Planned"; 
     cell.myImageView.image = [UIImage imageNamed:@"restburgerking.png"]; 
     break; 
    case 2: 
     cell.primaryLabel.text = @"Appointment with Joey"; 
     cell.secondaryLabel.text = @"2 Hours"; 
     cell.myImageView.image = [UIImage imageNamed:@"restburgerstory.png"]; 
     break; 
    case 3: 
     cell.primaryLabel.text = @"Call With Client"; 
     cell.secondaryLabel.text = @"Planned";   
     cell.myImageView.image = [UIImage imageNamed:@"restkfc.png"]; 
     break; 
    case 4: 
     cell.primaryLabel.text = @"Appointment with Joey"; 
     cell.secondaryLabel.text = @"2 Hours"; 
     cell.myImageView.image = [UIImage imageNamed:@"restmcdonalds.png"]; 
     break; 
    default: 
     break; 
} 
return cell; 
} 

/* 
    // Override to allow orientations other than the default portrait orientation. 
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    } 
    */ 

- (void)didReceiveMemoryWarning { 
// Releases the view if it doesn't have a superview. 
[super didReceiveMemoryWarning]; 

// Release any cached data, images, etc that aren't in use. 
} 

    - (void)viewDidUnload { 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
[super dealloc]; 
} 

@end 

而头文件如下:

#import <UIKit/UIKit.h> 

@interface RestListViewController : UITableViewController { 
NSMutableArray  * myStrings; 
} 
@property(nonatomic, retain)NSMutableArray * myStrings; 

@end 

回答

2

您需要添加表示泰伯维

//.m 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 10; // numbers of rows 
} 
+1

显示扩展的UITableView类的行数委托的方法没有必要执行代表分配,因为他们已被分配 – WhiteTiger 2012-04-07 23:51:24

+0

谢谢WhiteTiger,问题解决了:) – dramaticlook 2012-04-08 00:02:41