I am getting the following crash:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
I do have the following in my ViewDidLoad:
[self.collectionView registerClass:[UICollectionViewCell class]
forCellWithReuseIdentifier:#"Cell"];
And the line that crashes is in the cellForItemAtIndexPath callback:
UICollectionViewCell *cell = [collectionView
dequeueReusableCellWithReuseIdentifier:#"Cell" forIndexPath:indexPath];
I've been searching for hours but cannot find any solution. I've tried subclassing the UICollectionViewCell but get the same error.
With breakpoints I have determined that the registerClass line is being executed before the dequeueReusableCellWithReuseIdentifier callback is executed.
I had this problem because I was calling registerClass before I was instantiating my table view object. Working code :
self.tableView = [[UITableView alloc] initWithFrame:self.view.frame];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView reloadData];
Also, don't forget the difference between a cell (register... forCellWithReuseIdentifier) and a supplementary view (register... forSupplementaryViewOfKind).
I was dequeing it correctly with the supplementary (header/footer) type, but I accidentally registered it as a cell type. Duh.
If you happen to experience this, in UICollectionViewController or UITableViewController, do as what rob mayoff said and make sure that your Collection View or Table View is hooked up property in your Storyboard.
Another common mistake is in the Storyboard you forgot to give the right CollectionID or CellID.
Once when I was working on collection view cells, I wrote:
static NSString *identifier = #"cell ";
Looking carefully, you will see an extra space at the end of the identifier string. After realizing my mistake, I hope this will be helpful to someone.
Reference:
could not dequeue a view of kind: UICollectionElementKindCell with identifier
Related
I am connecting two storyboard view controllers programmatically. I am getting the following assertion:
*** Assertion failure in -[FullGalleryViewController loadView], /SourceCache/UIKit_Sim/UIKit-2380.17/UICollectionViewController.m:104
My code is as follows:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
FullScreenViewController *myVC = (FullScreenViewController *)[storyboard instantiateViewControllerWithIdentifier:#"FullScreenViewControllerId"];
[self presentViewController:myVC animated:YES completion:nil];
I have set the storyboard id to be FullScreenViewControllerId. I don't understand where am I going wrong.
How can I fix this error?
You instantiate FullScreenViewController and assertion failure is in FullGalleryViewController. It's not the same class.
I have a dynamically generated button on a detailviewcontroller (uisplitviewcontroller) that uses a uinavigation that when you tap will popover a uitableviewcontroller. The uitableviewcontroller pops up without any problems if I'm testint it with 0 sections. But when I change my section to 1 like so:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
It would give this error:
NSInternalInconsistencyException', reason: 'unable to dequeue a cell
with identifier MatchCell - must register a nib or a class for the
identifier or connect a prototype cell in a storyboard'
on this part:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Also, I noticed that, when stepping in the code , it would go through the numberOfSectionsInTableView and numberOfRowsInSection more than once (usually twice or sometimes three times).
Any thoughts on what I'm doing wrong?
Hy all.
Since i am using IOS 5 , therefore i am using storyboard.
In the older versions, i could easily write initWithNibName:#"Details", and it worked like a charm.
Now in storyboard, and since i am not using any XIB file, i need to do the same thing.
Here's a snippet of my code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Get the selected country
NSString *selectedAuthors = [theauthors objectAtIndex:indexPath.row];
//Initialize the detail view controller and display it.
Details *dvController = [[Details alloc] initWithNibName:#"Details" bundle:nil];
dvController.selectedAuthors = selectedAuthors;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
My new Snippet :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Get the selected country
NSString *selectedAuthors = [theauthors objectAtIndex:indexPath.row];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard.storyboard" bundle:nil];
Details *dvController = [storyboard instantiateViewControllerWithIdentifier:#"Details"]; //Or whatever identifier you have defined in your storyboard
//Initialize the detail view controller and display it.
//Details *dvController = [[Details alloc] init/*WithNibName:#"Details" bundle:nil*/];
dvController.selectedAuthors = selectedAuthors;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
Application Log :
2012-07-17 16:30:15.760 AuthorsApp[6534:f803] WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in <AuthorVC: 0x6857ba0>. Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior. This method will no longer be called in a future release.
2012-07-17 16:30:16.167 AuthorsApp[6534:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x6867750>) doesn't contain a view controller with identifier 'Details''
*** First throw call stack:
(0x1595022 0x1726cd6 0x500fef 0x3151 0x1675c5 0x1677fa 0x9fc85d 0x1569936 0x15693d7 0x14cc790 0x14cbd84 0x14cbc9b 0x147e7d8 0x147e88a 0xd6626 0x1dc2 0x1d35)
terminate called throwing an exception(lldb)
Latest Application Log:
2012-07-17 16:35:15.352 AuthorsApp[6600:f803] WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in <AuthorVC: 0x688d810>. Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior. This method will no longer be called in a future release.
2012-07-17 16:35:15.912 AuthorsApp[6600:f803] Everything is ok now !
(lldb)
Final Log
Couldn't register com.test.erc.AuthorsApp with the bootstrap server. Error: unknown error code.
This generally means that another instance of this process was already running or is hung in the debugger.(lldb)
You could instantiate the controller that is located in your storyboard like this:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"myStoryboard" bundle:nil];
Details *dvController = [storyboard instantiateViewControllerWithIdentifier:#"Details"]; //Or whatever identifier you have defined in your storyboard
Another option since you're using Storyboards would be using segues for the transitions. Here is a nice example. One thing that you get for free with segues is that the destination controller gets instantiated automatically for you. The delegate method looks like this:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:#"Details"]){
Details *dvController = (Details *)[segue destinationViewController];
// Pass any data to destination controller
// The transition is handled by the segue and defined in the Storyboard ('push' for example)
}
}
EDIT
Here is a screenshot for easy reference:
I have this code to load an NSView from a NIB and add it to another NSView:
// INIT
- (void)awakeFromNib {
// Load nib
DNListViewController *listViewController = [[DNListViewController alloc] initWithNibName:#"ListView" bundle:nil];
// Add view to window
[listViewController.view setFrame:detailView.frame];
[detailView addSubview:listViewController.view];
// MEM
[listViewController release];
}
All outlets are connected right, but nothing shows up. I don't understand why! Can someone help me? Thanks.
This is about NSViews, not UIViews!
Oh, I fixed it already. Nevermind, I'll let is stay here for people from the future.
[listViewController.view setFrame:detailView.frame];
must be
[listViewController.view setFrame:detailView.bounds];
A buddy of mine asked for a quick sample of code for an app skeleton that would use a TableView to call a TabView. I estimated an hour.
After more hours than I want to admit messing around in IB, I gave up and implemented the following code.
Can anyone tell me how to do this in IB? I was careful (I thought) to make all the right connections, but no go. I even had another (working) app where I went through and step-by-step made the same connections. I got errors about "Changing the delegate of a tab bar managed by a tab bar controller is not allowed..." (This when I connected the TabBar's delegate to the File's owner, even though another app was working fine with that setting)
Until I wrote this code, I never got the tabbar view, only the view that came with the view xib... (I tested by putting a label on the view).
Thanks in advance...
UITabBarController *tabBarController = [[[UITabBarController alloc] initWithNibName:nil bundle:nil] autorelease];
NumberOneViewController *numberOneViewController = [[[NumberOneViewController alloc] initWithNibName:#"NumberOneViewController" bundle:nil] autorelease];
NumberTwoViewController *numberTwoViewController = [[[NumberTwoViewController alloc] initWithNibName:#"NumberTwoViewController" bundle:nil] autorelease];
NumberThreeViewController *numberThreeViewController = [[[NumberThreeViewController alloc] initWithNibName:#"NumberThreeViewController" bundle:nil] autorelease];
NumberFourViewController *numberFourViewController = [[[NumberFourViewController alloc] initWithNibName:#"NumberFourViewController" bundle:nil] autorelease];
tabBarController.viewControllers = [NSArray arrayWithObjects:numberOneViewController, numberTwoViewController,
numberThreeViewController, numberFourViewController, nil];
[self.navigationController pushViewController:tabBarController animated:YES];
self.view = tabBarController.view; in the viewDidLoad method of the TabBarController delegate class fixed it...
Ah well, surely someone else will run into the same thing and hopefully this will help them...