1

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

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;

}

我只是在滚动视图中滚动页面时不会更改 LABLE 文本。

4

3 回答 3

2

尝试更换

temp_array = [[dataarray mutableCopy] autorelease];

temp_array = [[NSMutableArray alloc] initWithArray: dataarray];
于 2013-11-09T13:00:57.063 回答
1

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

temp_array = [dataarray mutableCopy];
于 2013-11-09T13:57:47.950 回答
1

将此添加到 viewDidLoad:temp_array=[[NSMutableArray alloc]init]以对其进行初始化。

于 2013-11-09T12:27:20.830 回答