iPhone:在tableview中实现“Show More”时出现异常

时间:2012-01-19 14:07:28

标签: iphone objective-c

我正在实现“显示更多”功能,就像在AroundMe中一样。实际上我没有遇到任何问题,直到我尝试将所有数据保存在整个字符串中并稍后传递给另一个视图。

当点击下面的“显示更多”按钮时,将调用代码:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[_connection release];
if(controlFlag == 1){

    additionalstring = [[NSString alloc] initWithData:additionalresponsedata encoding:NSUTF8StringEncoding];
    self.additionalresponsedata = nil;
    NSArray* addresultsData = [additionalstring JSONValue];
    [loadingIndicator_2 stopAnimating];
    temp1 = [additionalstring substringFromIndex:4];

   int temp = totalstring.length - 1;// i set break point here

    NSLog(@"%d", temp);
    totalstring = [totalstring substringToIndex:temp];
    totalstring = [totalstring stringByAppendingString:@","];


    int addtotal = [addresultsData count];

    for (int i = 0; i < addtotal; i++){
        //choose a random loan
         //store retailerid   

    }

从服务器获取额外的字符串,每当用户点击“显示更多”时,我想一起保存为总字符串。

在我的程序中,第一次单击显示更多,看起来都很好,但是当第二次单击时,它会抛出异常:

 -[__NSCFData getCharacters:range:]: unrecognized selector sent to instance 0x737f210
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData getCharacters:range:]: unrecognized selector sent to instance 0x737f210'
*** First throw call stack:
(0x187a052 0x169ad0a 0x187bced 0x17e0f00 0x17e0ce2 0x178398e 0x1855c6e 0x17a3b6c 0x1822ce8 0xb0cb63 0xb0cad5 0x756b 0xb9ba59 0xb99e94 0xb9aeb7 0xb99e4f 0xb99fd5 0xadef6a 0x133dbbd 0x140a5ea 0x1334298 0x140a16b 0x1334137 0x184e97f 0x17b1b73 0x17b1454 0x17b0db4 0x17b0ccb 0x167c879 0x167c93e 0x1a6a9b 0x21bd 0x2135 0x1)
terminate called throwing an exception(gdb) 

谢谢j

1 个答案:

答案 0 :(得分:0)

为什么要发布有效的“_connection”变量?我不明白你在那里释放什么。尝试删除该行。对不起,如果我错了。