任何人都可以帮助我解决这个错误。我尝试很多,但每次都遇到相同的错误。
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中滚动页面时,我只是不会更改标签文本。
最佳答案
尝试更换
temp_array = [[dataarray mutableCopy] autorelease];
至
temp_array = [[NSMutableArray alloc] initWithArray: dataarray];
关于ios - EXC_BAD_ACCESS(Code = 2,address = 0x8)运行时线程原因,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19875853/