2016年1月17日 星期日

iOS筆記:UICollectionViewCell的一些問題

遇到的問題:[UICollectionViewCell imageCell]: unrecognized selector sent to instance

當客製化自己的CollectionViewCell時一定要記得修改viewDidLoad底下的cell名稱.

- (void)viewDidLoad {
    [super viewDidLoad];

    // Register cell classes, 自己客制的cell要記得改這裡!!
    [self.collectionView registerClass:[yourCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
}

問題:Storyboard CollectionView segue not being triggered

明明Cell有拉Segue但是怎麼點都不會前進到下一個View.

Root cause: Cannot create segues directly from cells in a storyboard because the CollectionView is populated dynamically through the data source.

Solution: Should use the collectionView:didSelectItemAtIndexPath: and perform the segue programatically using performSegueWithIdentifier:sender:.

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [self performSegueWithIdentifier:@"MySegueIdentifier" sender:self];
}

沒有留言:

張貼留言