2015-09-22 41 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

“不过我无法访问资料表”你能解释一下吗? – anhtu

+0

@anhtu,我解决了这个问题。问题是我没有将tableView分配为@属性(强,非原子)的IBOutlet UITableView * tableView:'这是我的问题的原因!我会关闭我的问题,谢谢! –

回答

1

解决

我和我的代码有问题与从iOS社区一些很大的帮助解决。问题是,我填充我UITableView与我viewDidLoad(),而不是创建一个@property (strong, nonatomic) IBOutlet UITableView *tableView;

相关问题