IN my program,I am setting the constraints for my view using nslayoutconstraints.the view consists of a tableview,collectionview and a main view.When the view is loaded,the app crashes with the following error
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(0x27126d67 0x34c61c77 0x27047237 0x2704701b 0xe1333 0xe0bc1 0x1c6ca7 0x1d24e1 0x9b59cb 0x9b59b7 0x9b9411 0x270ecc41 0x270eb361 0x27038981 0x27038793 0x2e3e8051 0x2a62a981 0x1d72b5 0x351fdaaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
The value of the tableview is "NIL"
NSDictionary *viewsDictionary = #{#"tableView":_tableView,
#"mainView": _mainView,
#"movieDetail":_movieDetailView
};
This dictionary is used to set the height constraint in the tableview as below
NSArray *constraint_V = [NSLayoutConstraint constraintsWithVisualFormat:#"V:[tableView(tableHeight)]"
options:0
metrics:metrics
views:viewsDictionary];
[_tableView addConstraints:constraint_V];
Why is it that the value of tableview is nil?This tablview is an IBOUTLET from storyboard.When i allocate memory programatically the code runs.but the tableview is not loaded with data.Can anyone get me the reason?
Thank you in advance
Make sure you're not calling this too early and the table view has not yet been created. Perhaps you are executing this code in "viewDidLoad", maybe try viewWillAppear, or viewDidLayoutSubviews.
Please ensure you're synthesizing correctly to that property.
#synthesize yourIBOutletTableView = _tableView;
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 have encountered a strange crash on my code.
Here's the code :
UIView *tableHeaderView = self.tableView.tableHeaderView;
CGRect frame = tableHeaderView.frame;
frame.size.height = 0;
tableHeaderView.frame = frame;
self.tableView.tableHeaderView = tableHeaderView;
The crash occurred on the last line of the code.
And, here is the log
Terminating app due to uncaught exception 'NSRangeException', reason:
'*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x345ae2a3 0x3c25397f 0x344f9b75 0x1a7055 0x363ebb8f 0x363d702b 0x363d7599 0x363d740d 0x3642b22b 0x1a0d77 0x363d5595 0x3642a14b 0x3642a091 0x36429f75 0x36429e99 0x364295d9 0x364294c1 0x364764d1 0x36428861 0x36428713 0x364a4399 0x364508fb 0x36691619 0x364a39b9 0x364a1fe7 0x26c8a1 0x221997 0x34ee96fd 0x34e291f9 0x34e29115 0x3428b45f 0x3428ab43 0x342b2fcb 0x344f474d 0x342b342b 0x3421703d 0x34583683 0x34582ee9 0x34581cb7 0x344f4ebd 0x344f4d49 0x380b82eb 0x3640a301 0x10819f 0x3c68ab20)
libc++abi.dylib: terminate called throwing an exception
I really don't have any idea what happened on my code.
Any advice are helpful for me!
Thank you.
You definitely initialise some array in your class firstly check your array by placing NSLog that it should have some value or it is null. I think it is null thats why they creating a problem.
If you want to change the headerView for a table, this is the proper way to do it:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:kHeaderFrame];
return headerView;
}
Hey when I push another view Controller i get this in my main.m
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
I am using this to push the view controller -
-(void)showMore:(UIButton *)sender
{
MoreViewController *moreViewController = [[MoreViewController alloc] init];
[self.navigationController pushViewController:moreViewController animated:YES];
}
I am sending the message here
[moreButton addTarget:self action:#selector(showSettings:) forControlEvents:UIControlEventTouchUpInside];
Here is my Error -
2013-09-25 18:16:03.186 Time Travel[1591:60b] Application windows are expected to have a root view controller at the end of application launch
2013-09-25 18:16:05.179 Time Travel[1591:60b] -[NSConcreteValue showSettings:]: unrecognized selector sent to instance 0x14e5ea70
2013-09-25 18:16:05.181 Time Travel[1591:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteValue showSettings:]: unrecognized selector sent to instance 0x14e5ea70'
* First throw call stack:
(0x2e1e5e8b 0x384e26c7 0x2e1e97b7 0x2e1e80b7 0x2e136e98 0x309a055f 0x309a04fb 0x309a04cb 0x3098c0f3 0x3099ff13 0x3099fbdd 0x3099ac09 0x3096ff59 0x3096e747 0x2e1b0f27 0x2e1b03ef 0x2e1aebdf 0x2e119541 0x2e119323 0x32e492eb 0x309d01e5 0x4cbd5 0x389dbab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
Does it crash on the first line or the second? Add a breakpoint to each and click the continue button to check which one.
If it's the former there might be some illegal code in your alloc/init for MoreViewController.
If it's the latter, maybe there some class/delegate methods (viewDidLoad, etc) are the culprit.
What is the error message during your crash? (Sometimes clicking the resume-play-button in the debugger in Xcode can reveal a bit more after a crash.)
I didnt find a method named showSettings: in the code you posted. You are pushing your viewController in method named showMore: So I think, the code should be like this:
[moreButton addTarget:self action:#selector(showMore:) forControlEvents:UIControlEventTouchUpInside];
Please check with this.
The error message saying showSettings: method is not found
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteValue **showSettings:**]: unrecognized selector sent to instance 0x14e5ea70'
And I've notified that you are using showMore: as the name of your method
-(void)showMore:(UIButton *)sender
maybe just change showMore to showSettings, or vice versa
I have a mystery problem with UICollectionView.
I add my collection view to my tableview cell like so:
UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
UICollectionView *collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100) collectionViewLayout:layout];
[collection setDataSource:self];
[collection setDelegate:self];
[collection setBackgroundColor:[UIColor whiteColor]];
[collection registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:#"Cell"];
collection.tag = kTagPhotoCollectionView;
[cell.contentView addSubview:collection];
I'm implementing all the necessary delegate and data source methods and you can see I've set the datasource and delegate and have implemented them in my header.
When I go and press a UIButton which displays a UIImagePickerController and the app crashes with this error:
2013-08-13 20:17:02.578 [619:60b] *** Assertion failure in -[PUCollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:], /SourceCache/UIKit/UIKit-2891/UICollectionView.m:1397
2013-08-13 20:17:35.502 Sparky[619:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView dataSource is not set'
*** First throw call stack:
(0x30a02ed3 0x3aa2b6c7 0x30a02da5 0x3138c72f 0x3305f647 0x32f4adf9 0x32f47139 0x32eea543 0x32b72feb 0x32b6e817 0x32b6e6a9 0x32b6e0bd 0x32b6decf 0x32b67bfd 0x309cdf71 0x309cb8ff 0x309cbc4b 0x30936541 0x30936323 0x353ca343 0x32f4f8a5 0x5f835 0x3af40ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
I have set the datasource, so I have no idea why this would occur.
I faced with the similar problem, but my app crashed after I programmatically pop my UICollectionViewController. In some reason (I think it's just a bug in SDK) self.collectionView was alive after its' controller destroy, thus causing this failure:
*** Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:], /SourceCache/UIKit/UIKit-2935.137/UICollectionView.m:1305
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView dataSource is not set'
The solution is just override -dealloc in UICollectionViewController and release self.collectionView manually. ARC code:
- (void)dealloc {
self.collectionView = nil;
}
Hope this will save time for somebody.
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:.