按钮单击

时间:2015-05-26 06:35:15

标签: ios uitableview

我在使用removeObjectAtIndex时遇到异常 我在这个论坛上搜索过,但是我找不到这个例外的正确解决方案。实际上,当我点击按钮时,我从服务器获取数据,我获得了成功,而且我还需要删除该行,但所选行不会被删除。

  

我的异常: - 由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:' - [ NSCFArray removeObjectAtIndex:]:发送到不可变对象的变异方法'   ***第一次抛出调用堆栈:   (       0 CoreFoundation 0x000000010cfd1c65 __exceptionPreprocess + 165       1 libobjc.A.dylib 0x000000010c46bbb7 objc_exception_throw + 45       2 CoreFoundation 0x000000010cfd1b9d + [NSException raise:format:] + 205       3 CoreFoundation 0x000000010cfca70e - [__ NSCFArray removeObjectAtIndex:] + 94       4 SkigitApplication 0x00000001097fab80 __20- [主页确认:] _ block_invoke + 272       5 SkigitApplication 0x00000001098c8628 __64- [AFHTTPRequestOperation setCompletionBlockWithSuccess:failure:] _ 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 个答案:

答案 0 :(得分:2)

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

<强>更新

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

NSMutableArray *request = someData;

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

NSMutableArray *request = [someData mutableCopy];

现在,你有一个可变数据。