内容未显示在UITableView中

0 objective-c uitableview ios xcode6

我想,以显示我的内容UITableView在我的UIViewController.

我的表视图是称为常规视图todayView这是一个UIViewController叫Calendar 我连接datasource,并delegate以Calendar和添加了所有的表视图的方法,但它仍然无法正常工作.目前,我的代码看起来像这样我有什么问题吗?

@implementation SecondViewController {
    NSMutableArray *tableData;
}

-(BOOL)prefersStatusBarHidden{
    return YES;
}

- (void)viewDidLoad {

    [super viewDidLoad];

    NSDate *today = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"MMMM dd, yyyy"];
    NSString *dateString = [dateFormatter stringFromDate:today];
    self.dateLabel.text = dateString;


    Event *e1 = [[Event alloc] init];
    e1.name = @"All School Mass";
    e1.time = @"All Day";

    [tableData addObject:e1];

    Event *e2 = [[Event alloc] init];
    e2.name = @"Tennis - Moreau Catholic vs James Logan";
    e2.time = @"4:00 pm at Moreau Catholic";

    [tableData addObject:e2];

    // Do any additional setup after loading the view, typically from a nib.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [tableData count];

}

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


    //Configure your cell
    Event *event = [tableData objectAtIndex:indexPath.row];
    cell.textLabel.text = event.name;

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

Pra*_*era 5

你有没有初始化tableData可变数组?我认为你没有初始化它,这就是为什么一切都在发生.

请分配

tableData = [NSMutableArray array]; 而不是添加一些对象.

否则tableData.count将始终返回零.所以不会显示任何数据.