Home Articles

单击按钮时删除UITableview中的选定行

Asked
Viewed 694 times
-1

我在使用 removeObjectAtIndex 时遇到异常 .
我找到了这个例外的正确解决方案 . 实际上,我获得了成功,我还需要删除该行,但所选行不会被删除 .

我的异常: - 由于未捕获的异常'NSInternalInconsistencyException'终止应用程序,原因:' - [NSCFArray removeObjectAtIndex:]:发送到不可变对象的mutating方法'***第一次抛出调用堆栈:(0 CoreFoundation 0x000000010cfd1c65 __exceptionPreprocess 165 1 libobjc.A名为.dylib 0x000000010c46bbb7 objc_exception_throw 45 2的CoreFoundation 0x000000010cfd1b9d [NSException提高:格式:] 205 3的CoreFoundation 0x000000010cfca70e - [__ NSCFArray removeObjectAtIndex:] 94 4 SkigitApplication 0x00000001097fab80 __20- [主页确认:] _ block_invoke 272 5 SkigitApplication 0x00000001098c8628 __64- [AFHTTPRequestOperation setCompletionBlockWithSuccess:失败:] _block_invoke46 40 6 libdispatch.dylib 0x000000011160f186 _dispatch_call_block_and_release 12 7 libdispatch.dylib 0x000000011162e614 _dispatch_client_callout 8 8 libdispatch.dylib 0x0000000111616a1c _dispatch_main_queue_callback_4CF 1664 9 CoreFoundation 0x000000010cf391f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH _QUEUE 9 10 CoreFoundation 0x000000010cefadcb __CFRunLoopRun 2043 11 CoreFoundation 0x000000010cefa366 CFRunLoopRunSpecific 470 12 GraphicsServices 0x000000010db6da3e GSEventRunModal 161 13 UIKit 0x000000010acf7900 UIApplicationMain 1282 14 SkigitApplication 0x00000001098c65bf main 111 15 libdyld.dylib 0x0000000111663145 start 1 16 ??? 0x0000000000000001 0x0 1)libc abi.dylib:以NSException类型的未捕获异常终止

这是我的代码:request是我的数组

In .h
NSMutableArray *request;

In .m


-(void)Confirm:(id)sender

{
NSString *test = [NSString stringWithFormat:@"WebserviceUrl"];

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];




[manager GET:test parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
 {

    NSLog(@"JSON: %@", responseObject);
    if([[responseObject valueForKey:@"Success"]integerValue])
    {

        request=[[responseObject valueForKey:@"info"]mutableCopy];
        NSLog(@"array=%@",request);
        frndcount=[[[request valueForKey:@"is_new"]objectAtIndex:0]mutableCopy];
        NSLog(@"frndcount=%@",frndcount);
        notification_id= [[[request valueForKey:@"notification_id"]objectAtIndex:0]mutableCopy];
        NSLog(@"notification_id=%@",notification_id);
        item_id= [[[request valueForKey:@"item_id"]objectAtIndex:0]mutableCopy];;
        NSLog(@"item_id=%@",item_id);
        frnd_count.text=[NSString stringWithFormat:@"%@",frndcount];

        if (deleteIndexPath==0) {
           [request removeObjectAtIndex:deleteIndexPath.row];
            [self.msg_table deleteRowsAtIndexPaths:[NSArray arrayWithObject:deleteIndexPath] withRowAnimation:UITableViewRowAnimationFade];


        }



    }
}
     failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
         NSLog(@"Error: %@", error);
     }];
}

1 Answer

  • 2

    您的 request 对象是 NSArray 对象,它是不可变的 . 您应该将其更改为 NSMutableArray 并解决您的问题 .

    Update

    我不知道你是如何初始化这个对象的,但是如果你做的是这样的话:

    NSMutableArray *request = someData;
    

    引用对象可能不可变,因此您应该解决此问题:

    NSMutableArray *request = [someData mutableCopy];
    

    现在,您有一个可变数据 .

Related