运行时EXC_BAD_ACCESS(代码= 2,地址= 0x8)线程原因

时间:2013-11-09 12:18:10

标签: ios iphone objective-c

任何人都可以帮我解决这个错误。我尝试了很多但每次都得到同样的错误。

NSMutableArray *temp_array;

- (void)viewDidLoad
{ 

//... other code
 NSArray *dataarray = [[[mydata objectAtIndex:0] objectForKey:@"concept"] componentsSeparatedByString:@";"];
    temp_array = [[dataarray mutableCopy] autorelease];
}


-(void) setTitle:(NSString *)design_no
{

    productLbl.text = [[NSString stringWithFormat:@"%@",[temp_array objectAtIndex:[design_no intValue]]] autorelease];

    // I got error at this place like EXC_BAD_ACCESS(Code=2,address=0x8) thread cause while runtime.

}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender{

    CGFloat pageWidth = sender.frame.size.width;
    int page = floor((sender.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    if (page==previousPage_) {
        return;
    }

    //incase we are still in same page, ignore the swipe action

    [self setTitle:[NSString stringWithFormat:@"%i",page]];

}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollViewd;{
    CGFloat pageWidth = scrollViewd.frame.size.width;
    previousPage_ = floor((scrollViewd.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

}

当我在scrollview中滚动页面时,我只是不会更改LABLE文本。

3 个答案:

答案 0 :(得分:2)

尝试替换

temp_array = [[dataarray mutableCopy] autorelease];

temp_array = [[NSMutableArray alloc] initWithArray: dataarray];

答案 1 :(得分:1)

将此添加到viewDidLoad:temp_array=[[NSMutableArray alloc]init]以初始化它。

答案 2 :(得分:1)

问题是因为,您自动发布了[dataarray mutableCopy]。像这样使用它:

temp_array = [dataarray mutableCopy];