2015-08-15 3 views
0

Я пытаюсь отобразить содержимое в моем UITableView в моем UIViewController.Содержимое не отображается в UITableView

Моего вида таблицы в обычном режиме просмотра называется 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; 
} 

ответ

5

настроите вы что tableData изменяемый массив? Я думаю, что вы hav'nt инициализировали его, поэтому все это происходит.

Пожалуйста выделить его

tableData = [массив NSMutableArray]; чем добавить некоторые объекты.

иначе tableData.count всегда будет возвращать нуль. , поэтому данные не будут отображаться.

0

Вы можете забыть этот метод
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
вы можете реализовать его и вернуть 1.

Смежные вопросы