ios - EXC_BAD_ACCESS(Code = 2,address = 0x8)运行时线程原因

标签 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中滚动页面时,我只是不会更改标签文本。

最佳答案

尝试更换

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/

相关文章:

ios - 以编程方式添加约束

iphone - 移植的iPad应用-应用ID和配置文件应该相同?

php - 新手-创建可以存储图片并返回url的服务器-iOS

iOS - 获得用户权限后立即更新 View

ios - 如何从另一个容器访问容器 View

ios - NSTimer 计时器WithTimeInterval 不调用选择器(Swift)

ios - 无法读取数据,因为它的格式不正确 - HTTP 网络

iphone - 缩放时找到 UIScrollView 的中心点

ios - 如何在 Storyboard 中设置导航栏的标题?

ios - 如何通过 TestFlight 测试 Facebook Audience Network 广告?