簡體   English   中英

單擊按鈕時刪除UITableview中的選定行

[英]Deleting Selected row in UITableview when Button click

使用removeObjectAtIndex出現異常。
我已經在該論壇中搜索過,但沒有找到針對此Exception的正確解決方案。 實際上,當我單擊按鈕時,我正在從服務器獲取數據,獲得了成功,並且還需要刪除該行,但是所選行並未刪除。

我的例外:-由於未捕獲的異常'NSInternalInconsistencyException'而終止應用程序,原因:'-[ NSCFArray removeObjectAtIndex:]:將變異方法發送到不可變對象'***首先拋出調用堆棧:(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- [HomePage確認:] _ 20_AF [塊-申請書]:0-0 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_ 隊列 + 9 10 CoreFoundation 0x000000010cefadcb __CFRunLoopRun + 2043 11 CoreFoundation 0x000000010cefa366 CFRunLoopRunSpecific + 470 12 GraphicsServices 0x000000010db6da3e GSEventRunModal + 161 13 UIKit 0x000000010acf7900 UIApplicationMain + 1282 14 SkigitApplication 0x00000001dy dy ++ dyb 16lib 0x00000001dy dy ++ lib 0 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);
     }];
}

您的request對象是一個不可變的NSArray對象。 您應該將其更改為NSMutableArray並解決問題。

更新資料

我不知道您如何初始化該對象,但是如果您正在執行以下操作:

NSMutableArray *request = someData;

引用對象可能是不可變的,因此您應該這樣做:

NSMutableArray *request = [someData mutableCopy];

現在,您有了可變數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM