0

これは私のエラーです:

キャッチされなかった例外によるアプリの終了'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を含む行を削除できるようにするにはどうすればよいですか?

4

2 に答える 2

1

どうもありがとう!!!

私の問題は最初は間違ったコードだったと思います;-)そして次に私は連続して表示された通知が2つのことであることを忘れました!したがって、最初にtheNotificationを削除し、2回目にtableViewのtheRowを削除する必要があります;-)

これが私のコードです-お気軽に;-)

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// If row is deleted, remove it from the list.
     if (editingStyle == UITableViewCellEditingStyleDelete)
           {

            // DELETE theNotification defined in (UITableViewCell *)tableView:{}
            [[UIApplication sharedApplication] cancelLocalNotification:notifcation];

            // DELETE theRow
            [notificationsArray removeObjectAtIndex:indexPath.row];
            [tableView deleteRowsAtIndexPaths:[NSMutableArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];

            [tableView reloadData];
    }    

}

YEEAARRR私はとても幸せです;-)とにかくコーディングで本当に新しいです;-)-だから誰かがより良い方法を持っているなら私を訂正してください:-)

于 2011-11-05T14:30:26.527 に答える
0

初期化に関しては、次のように可変配列を作成できます。

NSMutableArray *_notifArray = [NSMutableArray arrayWithArray:[[UIApplication sharedApplication] scheduledLocalNotifications]];

そして、おそらくそれも保持する必要があります。

行の削除に関して、reloadDataの呼び出しについて疑問に思います。前の行のDeleteRows...によってテーブルビューが更新されるため、これは必要ないと思います。それがメッセージの原因である可能性もあるのではないかと思います。もちろん、これはDeleteRowsの後に呼び出されますが、これがすべてどのように順序付けられているかを知る実際の方法はありません。また、DeleteRowsが完了する前にリロードがnumberOfRowsを照会すると、メッセージが表示される可能性があります。

お役に立てれば。

于 2011-11-04T13:01:07.780 に答える