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
「不過我無法訪問資料表」你能解釋一下嗎? – anhtu
@anhtu,我解決了這個問題。問題是我沒有將tableView分配爲@屬性(強,非原子)的IBOutlet UITableView * tableView:'這是我的問題的原因!我會關閉我的問題,謝謝! –