UICollectionView Exception Crash - ios

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.

Related

Peek in iOS 9 App Crashing

I am trying to do Peek and Pop in my iOS 9 capable app. The view in question has a UITableView, so I have in my code:
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {
// check if we're not already displaying a preview controller
if ([self.presentedViewController isKindOfClass:[WebViewController class]]) {
return nil;
}
// shallow press: return the preview controller here (peek)
self.webViewController = [[[WebViewController alloc] initWithNibName:#"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
return self.webViewController;
}
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
// deep press: bring up the commit view controller (pop)
self.webViewController = [[[WebViewController alloc] initWithNibName:#"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
[self showViewController:self.webViewController sender:self];
}
WebViewController is the ViewController I have already set up to display the content when the row of the tableview is selected. The error I get is:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString stringByAppendingString:]: nil argument'
*** First throw call stack:
(0x182160f5c 0x19764bf80 0x182160ea4 0x182fb8868 0x1001307a4 0x1876cf9ac 0x1876cf720 0x187a025f8 0x187960844 0x18796cde4 0x1876a91e4 0x182117c30 0x1821159d4 0x182115e04 0x182044dc0 0x18d4e0088 0x18771ef60 0x10014ca68 0x197e6a8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
Your log it's saying exactly what is wrong with your code:
-[__NSCFConstantString stringByAppendingString:]: nil argument'
You are performing stringByAppendingString passing a value that is nil
Also, autorelease is not used anymore if you are using ARC (it's default by now)

tableview is nil and the app crashes ios xcode

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;

Nib Navigation Thread 1: signal SIGABRT

I have a button in my ProfileView view controller nib called that when pressed I went to display the OptionsView view controller.
In my ProfileView.m file I have this is viewDidLoad:
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Options" style:UIBarButtonItemStylePlain target:self action:#selector(actionOptions)];
and then I have:
- (void)actionOptions
{
OptionsView *screen = [[OptionsView alloc] initWithNibName:#"OptionsView" bundle:Nil];
[self.view addSubview:screen.view];
}
But whenever I tap the button I get a Thread 1: signal SIGABRT with the following console output:
2014-11-24 13:43:54.107 app[2161:5537921] didFailToRegisterForRemoteNotificationsWithError Error Domain=NSCocoaErrorDomain Code=3010 "remote notifications are not supported in the simulator" UserInfo=0x7ff7c2c365d0 {NSLocalizedDescription=remote notifications are not supported in the simulator}
2014-11-24 13:43:55.673 app[2161:5537921] *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:7344
2014-11-24 13:43:55.676 app[2161:5537921] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
You have SIGABRT because datasource of tableview that displayed in OptionsView is not returning valid cell from tableView:cellForRowAtIndexPath: method.
Code that you are posted is OK.

FBLoginView crashes with NSInvalidArgumentException

I'm experiencing a weird crash using FBLoginView.
Scenario for crash: My view with a FBLoginView instance loads and I don't login, I go back to my previous view and load my view with the FBLoginView instance again, this causes the app to crash and I can't see what I'm doing wrong.
It's working fine if I login and repeat the same thing.
Crash log:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString stringByAppendingString:]: nil argument'
I found this: Very weird NSInvalidArgumentException with addSubview FBLoginView - which kind of describes the same problem, but I don't use FBLoginView in multiple views.
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
if (!self.loginView) {
self.loginView = [FBLoginView new];
self.loginView.readPermissions = #[#"public_profile", #"email", #"user_friends"];
self.loginView.delegate = self;
[self.view addSubview:self.loginView];
}
}
Any suggestions?

A strange UITableView crash : NSRangeException

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;
}

Resources