2015-09-22 3 views
1

У меня возникли проблемы с попыткой вызвать мои UITableView вместо других методов.Обновление UITableView, когда пользователь выбирает дату из календаря

В основном я пытаюсь, чтобы мой код сделать это:

--Когда пользователь нажимает на дату в календаре, он будет обновлять UITableView и заселить его с определенным объектом (то есть ресторан).

- Я считаю, что логика кода должна войти в мой метод (VRGCalendarView *)calendarView dateSelected. Однако я не могу получить доступ к tableData.

#import "VRGViewController.h" 

@interface VRGViewController() 

@end 

@implementation VRGViewController{ 
    NSArray *calendarTableData; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    VRGCalendarView *calendar = [[VRGCalendarView alloc] init]; 
    calendar.delegate=self; 
    calendar.center = self.view.center; 
    [self.view addSubview:calendar]; 
    [self calendarTableViewData]; 
} 

#pragma mark - Calendar Code 

-(void)calendarView:(VRGCalendarView *)calendarView switchedToMonth:(int)month targetHeight:(float)targetHeight animated:(BOOL)animated { 
    if (month==[[NSDate date] month]) { 
     NSArray *dates = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:5], nil]; 
     [calendarView markDates:dates]; 
    } 
} 

-(void)calendarView:(VRGCalendarView *)calendarView dateSelected:(NSDate *)date { 
    NSLog(@"Selected date = %@",date); 

    **//When ever a user clicks on a data in the calendar, the date will be NSLogged. I think that my logic should go here for when a user clicks on the date it will update the tableview - however I am unable to access the tableData which is specified in another method** 

    //[tableData reloadData]; 

} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 


#pragma mark - User Defined Table View Methods 

-(void)calendarTableViewData{ 
    calendarTableData = [[NSArray alloc]initWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"Green Tea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and Cheese Panini", nil]; 
} 


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


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *simpleTableIdentifier = @"Services"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
} 
    cell.textLabel.text = [calendarTableData objectAtIndex:indexPath.row]; 

    return cell; 
} 


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    NSLog(@"You have selected: %@",cell.text); 
} 


@end 
+0

«Однако я не могу получить доступ к tableData», можете ли вы объяснить больше? – anhtu

+0

@anhtu, я решил проблему. Проблема заключалась в том, что я не назначал tableView как '@property (сильный, неатомный) IBOutlet UITableView * tableView:' который был причиной моей проблемы! Я забуду свой вопрос, спасибо! –

ответ

1

решаемых

Вопрос у меня был с моим кодом был решен с некоторой большой помощью со стороны сообщества IOS. Проблема заключалась в том, что я заполнял свой UITableView в своем viewDidLoad() вместо создания @property (strong, nonatomic) IBOutlet UITableView *tableView;

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