2013-06-27 50 views
-2

我建立了一個帶有UITableView的ViewController(帶有xib)。我將視圖控制器設置爲用作表視圖的數據源和委託。一切似乎都已到位,但我無法控制單元格數據,因爲CellForRow ...永遠不會被調用。CellForRow ..從來沒有被稱爲

我的.h

#import <UIKit/UIKit.h> 
@interface MyViewController : UIViewController <UITableViewDataSource,UITableViewDelegate> 


@property IBOutlet UITableView *tableView; 

@end 

我的.m

#import "MyViewController.h" 

@interface MyViewController() 

@end 

@implementation MyViewController 

- (id)init{ 
self = [super init]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 

} 
return self; 
} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

self.tableView.delegate = self; 
self.tableView.dataSource = self; 

[self.view addSubview:self.tableView]; 

// Uncomment the following line to preserve selection between presentations. 
// self.clearsSelectionOnViewWillAppear = NO; 

// Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
// self.navigationItem.rightBarButtonItem = self.editButtonItem; 
} 


#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
#warning Potentially incomplete method implementation. 
// Return the number of sections. 
return 0; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
#warning Incomplete method implementation. 
// Return the number of rows in the section. 
return 0; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

// Configure the cell... 

cell.textLabel.textColor = [UIColor blackColor]; 
cell.textLabel.text = @"SOMETHING"; 

return cell; 
} 

回答

11

因爲你有0行和0的部分。由於有0行和0個部分,所以不需要創建或訪問單元格,因此cellForRowAtIndexPath永遠不會發送消息。

相關問題