App就像日历
我想删除tableView中的特定行。每一行都由datepicker保存。 Title和Subtitle是perfekt。它显示了在datePicker中选择的名称和时间。
如果我创建了多个事件,我的tableView会以正确的顺序显示它。
此外,如果我在前11:10h比11:00h以混合间隔创建事件 但如果我想删除事件编号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];
}
}
泰伯维:
- (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;
}
答案 0 :(得分:1)
在方法中添加一些
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView.editing && editingStyle == UITableViewCellEditingStyleDelete)
{
[tableView beginUpdates];
[[UIApplication sharedApplication] cancelLocalNotification:notifcation];
[notificationsArray removeObjectAtIndex:indexPath.row];
// Animate the deletion from the table.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationLeft];
[tableView endUpdates];
[tableView reloadData];
}
}
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
// UITableViewCellEditingStyleNone;
return YES;
}