![](/img/trans.png)
[英]when I click button in collection view, i I can't pass value to next view controller
[英]When i click an item in my collection view i got this error
我有一個collectionview,但是當我嘗試單擊圖像時,它顯示此錯誤? 整個應用程序是一個標簽欄應用程序,因此所有其他標簽頁都可以使用。 除了最后一個標簽圖像。 iam從plist拍攝圖像以將其顯示到collectionview中,這是錯誤的
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI
objectAtIndex:]: index 0 beyond bounds for empty array'*** First throw call stack: (0x1e92012
0x1969e7e 0x1e47b44 0x58b91 0x56686 0x137cf 0x98f1c7 0x98f232 0x98f4da 0x9a68e5 0x9a69cb 0x9a6c76
`0x9a6d71 0x9a789b 0x9a7e93 0x9a7a88 0xd03e63 0xcf5b99 0xcf5c14 0xdaf5d9 0xdc1182 0xdc1394 0x197d705
0x9bb93c 0x9bb9ac 0x197d705 0x9bb93c 0x9bb9ac 0xb751d3 0x1e5aafe 0x1e5aa3d 0x1e387c2 0x1e37f44
0x1e37e1b 0x3c0f7e3 0x3c0f668 0x8adffc 0x287d 0x27a5) libc++abi.dylib: terminate called throwing an exception
這是didselect方法,並准備將該數組傳遞給另一個ViewController
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"bookItem"]) {
NSDictionary *currentBook = [[_freeBooks objectForKey:@"freebook"] objectAtIndex:[[[self.collectionView indexPathsForSelectedItems] objectAtIndex:0] row]];
NSLog(@"%@", currentBook);
GMMDetailpage *detailpage = (GMMDetailpage *)[segue destinationViewController];
detailpage.bookDetails = currentBook;
NSLog(@"%@",detailpage.bookDetails);
}
}
當前書籍的價值是印刷並且可以正常打印....但是在此之后,它執行其他系統代碼,然后顯示異常。
您正在執行兩個數組訪問,因此錯誤來自兩個數組之一為空的事實。
這兩個數組是
[self.collectionView indexPathsForSelectedItems]
和
[_freeBooks objectForKey:@"freebook"]
獨立檢查兩個數組,找出哪個是空數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.