0

配列内の行を削除しようとしています。編集ボタンを押した後、削除ボタンを押してから、赤いマイナスの小さなボタンを押します。シミュレーターで削除ボタンを押しても何も起こりません。誰かが私を助けてくれたらお願いします。これが私のコードです:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
    //here is where the magic doesn't happens
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [stories removeObjectAtIndex: storyIndex];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }

    NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"module"];

    // clean up the link - get rid of spaces, returns, and tabs...
    storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
    storyLink = [storyLink stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    storyLink = [storyLink stringByReplacingOccurrencesOfString:@"  " withString:@""];

    NSLog(@"link: %@", storyLink);
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:storyLink]];
}
4

1 に答える 1

0

次のことを行う必要があります..

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
    //here is where the magic doesn't happens
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [stories removeObjectAtIndex: storyIndex];

        //EDIT
        [tableView beginUpdates]; 
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
        [tableView endUpdates];

    }else{ //EDIT

         NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"module"];

        // clean up the link - get rid of spaces, returns, and tabs...
        storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
        storyLink = [storyLink stringByReplacingOccurrencesOfString:@"\n" withString:@""];
        storyLink = [storyLink stringByReplacingOccurrencesOfString:@"  " withString:@""];

        NSLog(@"link: %@", storyLink);
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:storyLink]];
    }
}
于 2013-11-06T16:18:40.763 に答える