これは私のエラーです:
キャッチされなかった例外によるアプリの終了'NSInternalInconsistencyException'、理由:'無効な更新:セクション0の行数が無効です。更新後の既存のセクションに含まれる行数(2)は、それに含まれる行数と同じである必要があります更新前のセクション(2)、そのセクションから挿入または削除された行の数(0が挿入、1が削除)、およびプラスまたはマイナスがそのセクションに出入りした行の数(0が移動、0が移動)アウト)。'
それが何を意味するのかは知っていますが、コードに間違いを見つけることができません。NSMutableArryのみを使用する必要があることを知っています。通常のNSArrayではありません。これが私が思うポイントです...
私のhで。ファイル:NSMutableArray * notifArray、IBOutlet UITableView * myTable;
コード:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
}
コード:
// Customize the appearance of table view cells.
- (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...
NSArray *_notifArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *notif = [_notifArray objectAtIndex:indexPath.row];
<...>
コード:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// If row is deleted, remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete) {
[notifArray removeObjectAtIndex:indexPath.row];
[self.myTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[myTable reloadData];
}
}
コード:
- (IBAction) scheduleAlarm:(id) sender {
[eventText resignFirstResponder];
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
// Get the current date
NSDate *pickerDate = [self.datePicker date];
// Break the date up into components
NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit )
fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
fromDate:pickerDate];
// Set up the fire time
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
// Notification will fire in one minute
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:[timeComponents second]];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
[dateComps release];
localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil)
return;
localNotification.fireDate = itemDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
// Notification details
localNotification.alertBody = [eventText text];
// Set the action button
localNotification.alertAction = @"View";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = 1;
// Specify custom data for the notification
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
localNotification.userInfo = infoDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];
[self.myTable reloadData];
}
この行をNSMutabelArrayに変更すると、エラーも発生します。「タイプ「NSArray*」の式で「NSMUtableArray」を初期化する互換性のないポインタ型
---> NSArray *_notifArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
では、localNotificationを含む行を削除できるようにするにはどうすればよいですか?