I know this question is other places on stackoverflow, but none of those solutions have worked for me. I have two tabs with table views that I want using the same datasource. The first tab's view controller is a subclass of UITableViewController. The second one is a simple UIViewController with its tableView set up in IB. I initially set up the view controller initializer to take the data source as an argument, but since that was crashing so much, I tried to simplify things by simply allocating it in my view controller. I have the Table View and datasource set up as follows:
#property (weak, nonatomic) IBOutlet UITableView *tableView; //Connected in IB
#property (strong, nonatomic) TableViewDataSource *data;
My program always crashes whenever I: [self.tableView setDataSource: data]; I tried putting that line in the viewDidLoad method, but my program still crashes. Here is my viewDidLoad method:
- (void)viewDidLoad
{
[super viewDidLoad];
data = [TableViewDataSource new]; //My data source object
NSLog(#"%#", data); //This isn't null, it says TableViewDataSource and then some address
[self.tableView setDataSource:data];
}
My first view controller works fine. It loads the data fine as well, so I don't believe I made any mistake in my datasource object. But every time I click on the second tab, the program crashes immediately. It doesn't crash if I leave out the data source assignment statement however.
Here is the crash:
2013-08-14 12:56:57.313 iPlanner[961:c07] *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:5471
2013-08-14 12:56:57.314 iPlanner[961:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
*** First throw call stack:
(0x1ca2012 0x10dfe7e 0x1ca1e78 0xb75665 0xd9c1b 0x6e40c 0xd9a7b 0xde919 0xde9cf 0xc71bb 0xd7b4b 0x742dd 0x10f36b0 0x229efc0 0x229333c 0x2293150 0x22110bc 0x2212227 0x22b4b50 0x39edf 0x1c6aafe 0x1c6aa3d 0x1c487c2 0x1c47f44 0x1c47e1b 0x1bfc7e3 0x1bfc668 0x23ffc 0x298d 0x28b5)
libc++abi.dylib: terminate called throwing an exception
(lldb)
'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
This is what is causing your app to crash. Something in the logic of your tableView:cellForRowAtIndexPath method is keeping a UITableViewCell from being returned. That log message says it all -- A UITableViewCell must be returned from tableView:cellForRowAtIndexPath:.
Related
I've a really strange error, and I cannot find the problem.
In my iPad APP I've a UINavigationController, a UITableViewController as master and a UIViewController containing a UIWebView as detail.
I launch the APP, the UITableViewController is shown. By segue I open the detail as usual. Then I have a back button in my detailviewcontroller that calls this method
[self.contentWebView setDelegate:nil];
[self.contentWebView stopLoading];
[self.navigationController popViewControllerAnimated:YES];
It gets poped and the master is shown again. Its
- (void)viewWillAppear:(BOOL)animated
gets called, but then I get the following error:
2014-06-06 15:56:58.156 Knowledge[356:60b] -[_UIWebViewScrollViewDelegateForwarder scrollViewWasRemoved:]: unrecognized selector sent to instance 0x170429f60
2014-06-06 15:56:58.159 Knowledge[356:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UIWebViewScrollViewDelegateForwarder scrollViewWasRemoved:]: unrecognized selector sent to instance 0x170429f60'
*** First throw call stack:
(0x189582f50 [...] 0x196553aa0)
libc++abi.dylib: terminating with uncaught exception of type NSException
BUT, this happens only on the iPad Air... older iPads work as expected
UPDATE:
I added now the command [self.contentWebView removeFromSuperview]; after "stopLoading" and now the error is happing right up there.
Please ignore this answer if you are not touching scroll view's (of the web view) delegate reference.
I was facing the same strange error. After some investigation, I found that it was happening because scroll view's (of the web view) delegate was altered in controller's viewDidLoad method:
[self webView].scrollView.delegate = self;
In some cases, scroll view invokes delegate method(s) even after your view controller is destroyed. This should be prevented by weak delegate reference, but for some reason scroll view calls delegate method on deallocated (zombie) object anyway. I assume this is a bug in the framework.
So here what you can do: set delegate reference to nil in your controller's dealloc method:
- (void)dealloc
{
[self webView].scrollView.delegate = nil;
}
After deallocation, scroll view will be prevented from calling any method on no longer existing controller.
I am new to using this method so I could be doing this completely wrong so here is my code:
#property (nonatomic, weak) ConverterViewController *converterViewController;
#property (nonatomic, weak) CalculatorViewController *calculatorViewController;
If I am understanding this code correctly, these are acting as references to Two different ViewControllers.
Then I have this in my viewDidAppear method:
[self addChildViewController:_converterViewController];
[_converterViewController didMoveToParentViewController:self];
[self.view addSubview:_converterViewController.view];
I am getting an NSException at the first line when I try and add it as a child view controller. So not knowing whether or not this should then call some methods in my ConverterViewController class I put some breakpoints within that class both the initWithNibName and viewDidLoad methods and I found that neither of these methods are being called, so Im not exactly sure what is wrong. Then again Im not really sure what could go wrong so any help is greatly appreciated.
This is all I get from the console:
libc++abi.dylib: terminating with uncaught exception of type NSException
Updated Answer:
[self addChildViewController:_converterViewController]; does not create the converterViewController.
It simply takes the converterViewController object and adds it as a childViewController to self.
You will need to allocate memory and instantiate the object converterViewController before -addChildViewController: or else it's value will be nil and nothing will happen.
So... something this:
_converterViewController = [[ConverterViewController alloc] initWithNibName:#"ConverterViewController"
bundle:nil];
//now... adding it as childViewController should work
[self addChildViewController:_converterViewController];
[_converterViewController didMoveToParentViewController:self];
//optional: give it a frame explicitly so you may arrange more childViewControllers
//[_converterViewController.view setFrame:CGRectMake(0,0,100,100)];
[self.view addSubview:_converterViewController.view];
There are so many cases for "Unrecognized Selector Sent To Instance", I don't think I will find mine in so many threads. Or if I do it will take a month or so.
To be short. I receive this error, and my situation is:
I have a table view displaying recipes that are fetched from Core Data. When segue fires, it gets destination controller (which is UITabBarController), and provides a recipe for it.
The code for the segue method is:
if ([segue.identifier isEqualToString:#"RecipeTabBarController"]) {
RecipeTabBarController *VC = segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Recipe *recipe = (Recipe*)[_controller objectAtIndexPath:indexPath];
VC.recipe = recipe;
}
TabBarController (which is the VC) has a property of a recipe, like so:
#property (nonatomic, strong) Recipe *recipe;
When I tap the cell, the segue fires, and the error occurs, with the following message from console:
2013-09-25 18:55:21.888 RecipeBank [974:60b] -[UITabBarController setRecipe:]: unrecognized selector sent to instance 0x15da8280
2013-09-25 18:55:21.892 RecipeBank [974:60b] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController setRecipe:]: unrecognized selector sent to instance 0x15da8280'
First throw call stack:
(0x30583f53 0x3abec6af 0x305878e7 0x305861d3 0x304d5598 0x6676f 0x3319f6f1 0x665b7 0x32e1232b 0x32ec5253 0x32d75971 0x32ced473 0x3054f1d5 0x3054cb79 0x3054cebb 0x304b7ce7 0x304b7acb 0x35185283 0x32d59a41 0x67711 0x3b0f4ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
RecipeTabBarController imports Recipe class in header and TableViewController that's performing segue imports RecipeTabBarController for it as well. So no mistake there.
What could be wrong?
Please help. Thanks.
Sounds like the class of the destination view controller is UITabBarController and not your own class RecipeTabBarController. Look in your storyboard as to how you have the segue set up and figure out why things are not what you expect.
I need to create a number of UIScrollViews dynamically and fill them with content. This is all good except when i set the delegate to self and pan the list i get this exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString scrollViewDidScroll:]: unrecognized selector sent to instance 0x7581230'
NSCFString obviously isn't my view controller (which implements the protocol UIScrollViewDelegate) so from what i gather somehow the memory gets messed up and it doesn't keep the reference correctly. Occasionally this can be something else too which strongly points to something being wrong with the memory
Here's the code to create the list:
for (NSUInteger i = 0; i < self.stories.currentStory.selectableWordCount; i++) {
UIScrollView *list = [[UIScrollView alloc] init];
list.alwaysBounceVertical = YES;
list.showsVerticalScrollIndicator = NO;
list.clipsToBounds = NO;
list.delegate = self;
list.pagingEnabled = YES;
[self.view addSubview:list];
.. // add UILabels to the list, set the frame, contentSize etc
[self.wordLists addObject:list]; // this is a #property (nonatomic, strong) NSMutableArray, declared in a private interface()
}
If i NSLog the delegate it's correct. respondsToSelector also matches fine. Interestingly if i comment out the scrollViewDidScroll: respondsToSelector: doesn't match any more and (probably because of this) the UIScrollView won't attempt to call this method any more. This then means that it can reach the delegate correctly to check for the method availability but when it gets called something goes wrong.
I'm targeting iOS5 with ARC. If this wasn't the case i would assume that i messed something up with the memory myself but now i don't have the same control.
I'm having a hard time debugging this issue, any help on how to proceed would be appreciated
D'uh. I was obviously looking in the wrong place. The view controller was added through a .xib and the view was pointing to a subview on the stage. However i needed to create an IBOutlet to the view controller in the main view controller to make sure it stays in memory. Hopefully this can help somebody else with a similar problem :)
I am using UILabel for custom cells in my UITableView. Heres all the code that I am using :
header file:
UILabel *timeLabels;
#property (nonatomic, retain) UILabel *timeLabels;
code file:
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
timeLabels=[[UILabel alloc] init];
timeLabels.textAlignment=UITextAlignmentLeft;
timeLabels.font=[UIFont boldSystemFontOfSize:12];
timeLabels.backgroundColor=[UIColor clearColor];
timeLabels.textColor=[UIColor blueColor];
- (void) layoutSubviews
frame=CGRectMake(boundsX+5, 5, 60, 45);
timeLabels.frame=frame;
[timeLabels release]
I am getting the following error on timeLabels.frame=frame;
2011-08-08 12:44:07.290 EncameoApp[2014:707] -[NSCFString setFrame:]: unrecognized selector sent to instance 0x136890
2011-08-08 12:44:07.361 EncameoApp[2014:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString setFrame:]: unrecognized selector sent to instance 0x136890'
Which is pretty strange given that timeLabels is not a NSString, but rather a UILabel !
Can anyone please let me know what I missed here ? Thanks.
I also faced this kind of problem, but i had solved this problem by set value of timeLabels as following:-
timeLabels.text = #"value";
instead of
timeLabels = #"value";
The code snippet you show is correct, anyway my guess is that you have very possibly a memory problem that makes your UILabel instance to be released at some point before layoutSubviews is executed, then that memory is reused by an NSString, so you get the error there.
In my experience, the most common case for this to happen is anyway erroneously overwriting timeLabels with the wrong value could produce the same result. This could be done within the class or from another class (that maybe tries to set the label value).
If you want to make a simple test, add
NSLog(#"timeLabels address %x", timeLabels);
both to init and to layoutSubviews to compare the two values and see that they differ (or maybe they don't, in this case you would have a memory corruption problem).
You should inspect your code, and post more of it if you need more help.