1
votes

I use storyboarding for my iOS application. I also need to use [[NSBundle mainBundle] loadNibNamed:@"myxib" owner:self options:nil]; method to load a nib file.

After I loaded the nib file, UICollectionViewCell* newCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"recentItemsCell" forIndexPath:indexPath]; starts giving runtime error. I think calling loadNibNamed method removes the registered cells (that are registered by storyboard) because when I delete the loadNibNamed line, I can dequeueCell without any problem.

is there any way to load a nib file for a view controller by not removing the prototype cell registrations made by the storyboard?

Thanks in advance

2
what is the run time error...?Adnan Aftab
it says that it could not found registered cell for that reuse identifier. Actually storyboard automatically registeres the prototype cell, but when I do loadNibNamed, it forgetsAliAx

2 Answers

0
votes

Try to load nib manuallay CustomCell *cell = (CustomCell*)[[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] objectAtIndex:0];

0
votes

If the cell is in storyboard , then why do you need to load it using loadNibNamed? If you want to make a separate class for the cell , you can subclass UICollectionViewCell and the call registerClass method in View Controller's viewDidLoad method. In this way you can load the cell which is in storyboard and declare all the properties related to cell in subclass you created. Hope i am clear.