CellForRow ..永远不会被召唤

时间:2013-06-27 20:35:59

标签: ios objective-c cocoa-touch

我使用UITableView设置了一个ViewController(带有xib)。我将视图控制器设置为表视图的数据源和委托。一切似乎都到位,但我无法控制单元格数据,因为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;
}

1 个答案:

答案 0 :(得分:11)

因为你有0行和0部分。由于有0行和0个部分......从不需要创建或访问单元格,因此永远不会向cellForRowAtIndexPath发送消息。