Приложение как календарь
Я хочу удалить определенные строки в моем tableView. Каждая строка сохраняется датером. Название и Субтитры - это совершенство. Он показывает имя и время, выбранное в DatePicker.
Если я создаю более одного события, мой tableView показывает его в правильном порядке.
- Событие №1 - 11:00 ч.
- Событие 2 - 11:10 ч.
- и т. Д.
Также, если я создаю событие в смешанных интервалах вначале 11: 10h, а не 11:00
Но если я хочу удалить Событие №1, то удаляю Событие №2
.
Кажется, мой код всегда удалял последнее сохраненное событие.
Режим редактирования:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// If row is deleted, remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[[UIApplication sharedApplication] cancelLocalNotification:notifcation];
[notificationsArray removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
[tableview reloadData];
}
}
Tableview:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
self.notificationsArray = [NSMutableArray arrayWithArray:[[UIApplication sharedApplication] scheduledLocalNotifications]];
notifcation = [self.notificationsArray objectAtIndex:indexPath.row];
//UILocalNotification *notif = [notificationsArray objectAtIndex:indexPath.row];
//NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
//UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];
//Was in der Zelle als Titel steht
//[[cell textLabel] setText:[notifcation alertBody]];
[[cell textLabel] setText:@"Event"];
//[cell.detailTextLabel setText:[notif.fireDate description]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd.MM.yyyy HH:mm"];
[[cell detailTextLabel] setText:[dateFormatter stringFromDate:notifcation.fireDate]];
[dateFormatter release];
return cell;
}