2013-11-09 83 views
1

任何人都可以幫助我解決這個錯誤。我嘗試了很多,但每次都得到相同的錯誤。EXC_BAD_ACCESS(代碼= 2,地址= 0x8)運行時線程原因

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文本,當我滾動頁面滾動視圖。

+0

你從哪裏得到'productLbl'?你應該在這裏使用一個屬性,所以它應該很可能是'self.productLbl' –

回答

2

嘗試更換

temp_array = [[dataarray mutableCopy] autorelease]; 

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

感謝兄弟的工作... –

+0

@LazyLion,不要忘了標記答案如果它幫助你接受。 –

1

添加該視圖到下載:temp_array=[[NSMutableArray alloc]init]初始化它。

+0

我加了這個,但得到了同樣的錯誤。 –

1

的問題是,因爲你自動釋放你的[DataArray中mutableCopy。像這樣使用它:

temp_array = [dataarray mutableCopy]; 
相關問題