我正在尝试为iOS7做提醒应用,但UITextField
和UIDatePicker
的数据不会显示在我的UITableViewCell
上。
表格单元格为空白(抱歉我的英文不好)
这是我的 AddToDoViewController.m ,其中包含UITextField
和UIDatePicker
- (IBAction)save:(id)sender {
[self.itemText resignFirstResponder];
//Get the Current date
NSDate *pickerDate = [self.datePicker date];
//Scheule the notification
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
localNotification.alertBody = self.itemText.text;
localNotification.alertAction = @"Show the To Do List";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
//Requested to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];
//Dismiss the view controller
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)cancel:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
这是我的 ToDoViewController.m ,它是从AddToDoViewController获取数据并显示它的tableView:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reloadTable)
name:@"reloadData"
object:nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
//Get list of local notification
NSArray *localNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *localNotification = [localNotifications objectAtIndex:indexPath.row];
//Display notification info
[cell.textLabel setText:localNotification.alertBody];
[cell.detailTextLabel setText:[localNotification.fireDate description]];
return cell;
}
- (void)reloadTable {
[self.tableView reloadData];
}