2017-05-16 45 views
1

我想通過prepareForSegue函數中的segue傳遞數據,但我一直在獲取exc_bad_access。prepareForSegue EXC_BAD_ACCESS at indexPath.row

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 

//NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowIndex inSection:0]; 
// Make sure your segue name in storyboard is the same as this line 
if ([[segue identifier] isEqualToString:@"itemListSegue"]) 
{ 
    itemList *vc = [segue destinationViewController]; 
    vc.inv = [inv_list objectAtIndex:indexPath.row]; 
    vc.title = vc.inv; 
} 
} 

波紋管是我得到了錯誤

enter image description here

編輯: inv_list聲明如下:

@interface downloadInv(){ 
NSMutableArray *inv_list; 
} 

在viewDidLoad中:

inv_list = [[NSMutableArray alloc] init]; 

內容:

enter image description here

vc.inv是在inv_list特定元件,我想當選擇一個表,傳遞到目的地視圖控制器。

它被宣佈如下:

@interface itemList : UITableViewController 

@property(nonatomic, strong) NSString *inv; 
@end 

enter image description here

任何人都知道如何解決這一問題?

在此先感謝。

+1

什麼是inv_list?它是數組嗎?確保你在'prepareforsegue'中獲得了正確的indexpat而不是零! – Lion

+1

請說明如何定義inv_list? –

+0

向我們展示列表是什麼,以及您嘗試填充的vc屬性是什麼。 –

回答

0

由於in_list未被宣告爲強屬性,因此可能會被釋放。如果它是由強勁性能像

@property (strong, nonatomic) NSMutableArray * inv_list;

0

能否請您檢查您的SEGUE標識,如果不是給予,可能會造成異常

否則:

@property(nonatomic,strong) NSString *inv_list; 
嘗試宣告它像這樣

它可以解決問題。