UITableView Crashing in iOS8 - ios

I Have Created a Table View with Custom cells. I placed that table view on a viewController and i am presenting that viewController whenever Required. it is Working fine in iOS6, iOS7. Coming to iOS8 it is getting crashed and showing an Error Message and in Some times it is getting Crashed Without Showing any Error Message Simply Showing EXC_BADACCESS:
-[DropDownViewTableViewCell tableView:heightForHeaderInSection:]: unrecognized selector sent to instance
and Below is the whole console Error Message.
2014-11-10 11:09:41.067 BML[1029:26620] -[DropDownViewTableViewCell tableView:heightForHeaderInSection:]: unrecognized selector sent to instance 0x7ccb05e0
2014-11-10 11:09:41.075 BML[1029:26620] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DropDownViewTableViewCell tableView:heightForHeaderInSection:]: unrecognized selector sent to instance 0x7ccb05e0'
*** First throw call stack:
(
0 CoreFoundation 0x0431c946 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x03fa1a97 objc_exception_throw + 44
2 CoreFoundation 0x043245c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x0426d3e7 ___forwarding___ + 1047
4 CoreFoundation 0x0426cfae _CF_forwarding_prep_0 + 14
5 UIKit 0x02a95449 -[UITableView _delegateWantsHeaderForSection:] + 370
6 UIKit 0x02c54935 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 169
7 UIKit 0x02c5b59c -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 302
8 UIKit 0x02c5b6c5 -[UITableViewRowData heightForTable] + 68
9 UIKit 0x02a6c98c -[UITableView _updateContentSize] + 395
10 UIKit 0x02a8f4a7 -[UITableView didMoveToWindow] + 76
11 UIKit 0x029fe5b9 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1703
12 UIKit 0x02a113e1 -[UIScrollView _didMoveFromWindow:toWindow:] + 65
13 UIKit 0x029fe23f -[UIView(Internal) _didMoveFromWindow:toWindow:] + 813
14 UIKit 0x029fe23f -[UIView(Internal) _didMoveFromWindow:toWindow:] + 813
15 UIKit 0x029fe23f -[UIView(Internal) _didMoveFromWindow:toWindow:] + 813
16 UIKit 0x029fe23f -[UIView(Internal) _didMoveFromWindow:toWindow:] + 813
17 UIKit 0x029fe23f -[UIView(Internal) _didMoveFromWindow:toWindow:] + 813
18 UIKit 0x029fe23f -[UIView(Internal) _didMoveFromWindow:toWindow:] + 813
19 UIKit 0x029f5517 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 154
20 UIKit 0x029f5475 -[UIView(Hierarchy) _postMovedFromSuperview:] + 458
21 UIKit 0x02a00f0d -[UIView(Internal) _addSubview:positioned:relativeTo:] + 2018
22 UIKit 0x029f386e -[UIView(Hierarchy) addSubview:] + 56
23 UIKit 0x02aa3b58 -[UITransitionView transition:fromView:toView:removeFromView:] + 1576
24 UIKit 0x0320826d -[UIViewControllerBuiltinTransitionViewAnimator animateTransition:] + 3551
25 UIKit 0x02aa91ad __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 2343
26 UIKit 0x02adc7ab __40+[UIViewController _scheduleTransition:]_block_invoke + 18
27 UIKit 0x029a20ce ___afterCACommitHandler_block_invoke + 15
28 UIKit 0x029a2079 _applyBlockToCFArrayCopiedToStack + 415
29 UIKit 0x029a1e8e _afterCACommitHandler + 545
30 CoreFoundation 0x0423f9de __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
31 CoreFoundation 0x0423f920 __CFRunLoopDoObservers + 400
32 CoreFoundation 0x0423535a __CFRunLoopRun + 1226
33 CoreFoundation 0x04234bcb CFRunLoopRunSpecific + 443
34 CoreFoundation 0x042349fb CFRunLoopRunInMode + 123
35 GraphicsServices 0x0684724f GSEventRunModal + 192
36 GraphicsServices 0x0684708c GSEventRun + 104
37 UIKit 0x029788b6 UIApplicationMain + 1526
38 BML 0x0014bc2d main + 141
39 libdyld.dylib 0x048b4ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
DropDownViewTableViewCell.h
#import <UIKit/UIKit.h>
#interface DropDownViewTableViewCell : UITableViewCell
#property (nonatomic, retain) IBOutlet UILabel *label;
#property (nonatomic, retain) IBOutlet UIImageView *imageVie;
#end
DropDownViewTableViewCell.m
#import "DropDownViewTableViewCell.h"
#implementation DropDownViewTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)awakeFromNib
{
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#end
TableViewImplementation
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 35;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.poiDataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
DropDownViewTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:#"myCell"];
if (!cell)
{
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
[tableView registerNib:[UINib nibWithNibName:#"DropDownView_iPhone" bundle:nil] forCellReuseIdentifier:#"myCell"];
cell = [tableView dequeueReusableCellWithIdentifier:#"myCell"];
}
else
{
[tableView registerNib:[UINib nibWithNibName:#"DropDownView_iPad" bundle:nil] forCellReuseIdentifier:#"myCell"];
cell = [tableView dequeueReusableCellWithIdentifier:#"myCell"];
CGRect frame;
frame =cell.label.frame;
frame.size.width +=50;
cell.label.frame=frame;
}
}
return cell;
}

Related

Displaying a popover crashes my iOS 8 app

A single popover that is called from multiple different view controllers without a problem except for one particular view controller. All the view controllers descend from the same parent class and thus use the same function to display the popover. The function uses presentPopoverFromRectto display the popover in question. On the problem view controller I can see the popover's viewDidLoadfire then the app crashes with a invalid argument exception. I have no idea what UILabel its talking about or why its trying to get its length.
-(IBAction) showNormSelector:(id)sender
{
if (self.normSelectionPopover == nil)
{
Ace_Metrix_iPad_2AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:#"AceMetrixMOBILEHD_Storyboard" bundle:[NSBundle mainBundle]];
NSMutableDictionary* mdic = [[NSMutableDictionary alloc]initWithCapacity:4];
mdic[NSLocalizedStringFromTable(#"Industry", appDelegate.stringTableName,#"")] = #(IndustryType);
mdic[NSLocalizedStringFromTable(#"Category", appDelegate.stringTableName,#"")] = #(CategoryType);
mdic[NSLocalizedStringFromTable(#"Subcategory", appDelegate.stringTableName,#"")] = #(SubCategoryType);
mdic[NSLocalizedStringFromTable(#"Brand", appDelegate.stringTableName,#"")] = #(BrandType);
NSArray* arr = #[NSLocalizedStringFromTable(#"Industry", appDelegate.stringTableName,#""),
NSLocalizedStringFromTable(#"Category", appDelegate.stringTableName,#""),
NSLocalizedStringFromTable(#"Subcategory", appDelegate.stringTableName,#""),
NSLocalizedStringFromTable(#"Brand", appDelegate.stringTableName,#"")];
self.popOver = (SelectorPopover*)[storyBoard instantiateViewControllerWithIdentifier:#"NormTypeSelector"];
[self.popOver setSelectionText:mdic];
[self.popOver setAllKeys:[NSMutableArray arrayWithArray:arr]];
[self.popOver setDelegate:self];
self.normSelectionPopover = [[UIPopoverController alloc] initWithContentViewController:self.popOver];
}
[self.popOver setCurrentSel:#(self.normType)];
[self.popOver.tableView reloadData];
[self.normSelectionPopover presentPopoverFromRect:self.normButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
SelectorPopover.m
#implementation SelectorPopover
#synthesize delegate;
#synthesize selectionText;
#synthesize allKeys;
#synthesize tag;
#synthesize currentSel;
-(void) viewDidLoad {
[super viewDidLoad];
self.clearsSelectionOnViewWillAppear = NO;
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) // before iOS 7
{
self.contentSizeForViewInPopover = CGSizeMake(135, [self.tableView rowHeight] * 4); // Depricated in iOS 7
}
else
{
self.preferredContentSize = CGSizeMake(135, [self.tableView rowHeight] * 4);
}
NSUInteger newIndex[] = {0, 0};
NSIndexPath* indexPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition: UITableViewScrollPositionNone];
}
/*
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
*/
/*
-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
-(void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
-(void) viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation // Deprecated in iOS6
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [self.selectionText count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"SelectCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSString* method = self.allKeys[indexPath.row];
cell.textLabel.text = method;
[cell.textLabel setTextColor:AMColorNeutralMidGrey38];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.accessoryView = nil;
NSNumber* uuid = (self.selectionText)[method];
if ([self.currentSel integerValue] == [uuid integerValue])
{
UIImageView *checkmark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"checkmark_blue.png"]];
cell.accessoryView = checkmark;
[cell.textLabel setTextColor:AMColorTradeMarkLightBlue];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
-(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
*/
/*
// Override to support rearranging the table view.
-(void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark -
#pragma mark Table view delegate
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.delegate)
{
NSString* key = self.allKeys[indexPath.row];
NSNumber* value = (NSNumber*) (self.selectionText)[key];
[self.delegate itemSelected:[value integerValue]];
}
}
#pragma mark -
#pragma mark Memory management
-(void) didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc. that aren't in use.
}
-(void) viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
[super viewDidUnload];
}
-(void) dealloc {
self.delegate = nil;
}
#end
SelectorPopover.h
#protocol ItemSelectdDelegate
-(void)itemSelected:(HierarchyType) item;
#end
#interface SelectorPopover : UITableViewController
#property (nonatomic, weak) id<ItemSelectdDelegate> delegate;
#property (nonatomic,strong) NSMutableDictionary* selectionText;
#property (nonatomic,strong) NSMutableArray* allKeys;
#property (nonatomic,strong) NSNumber* currentSel;
#property (nonatomic) NSInteger tag;
#end
Call Stack:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel length]: unrecognized selector sent to instance 0x7b60bd30'
*** First throw call stack:
(
0 CoreFoundation 0x03b49df6 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x02f52a97 objc_exception_throw + 44
2 CoreFoundation 0x03b51a75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x03a9a9c7 ___forwarding___ + 1047
4 CoreFoundation 0x03a9a58e _CF_forwarding_prep_0 + 14
5 CoreFoundation 0x03a33306 CFStringAppend + 374
6 CoreFoundation 0x03a30e2a __CFStringAppendFormatCore + 11754
7 CoreFoundation 0x03b26aa5 _CFStringCreateWithFormatAndArgumentsAux2 + 245
8 Foundation 0x004e9377 -[NSPlaceholderString initWithFormat:locale:arguments:] + 159
9 Foundation 0x004ecc22 +[NSString stringWithFormat:] + 89
10 UIKit 0x00aaa7a4 -[UIViewController _presentViewController:withAnimationController:completion:] + 2825
11 UIKit 0x00aad032 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 345
12 UIKit 0x00aace84 -[UIViewController presentViewController:animated:completion:] + 224
13 UIKit 0x01019011 -[UIPopoverController _presentShimmedPopoverFromRect:inView:permittedArrowDirections:animated:] + 217
14 UIKit 0x01019211 -[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:] + 355
15 Ace Metrix MOBILE HD 0x00111242 -[AdDetailViewController showNormSelector:] + 3762
16 libobjc.A.dylib 0x02f687cd -[NSObject performSelector:withObject:withObject:] + 84
17 UIKit 0x0094779d -[UIApplication sendAction:to:from:forEvent:] + 99
18 UIKit 0x0094772f -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
19 UIKit 0x00a7aa16 -[UIControl sendAction:to:forEvent:] + 69
20 UIKit 0x00a7ae33 -[UIControl _sendActionsForEvents:withEvent:] + 598
21 UIKit 0x00a7a09d -[UIControl touchesEnded:withEvent:] + 660
22 UIKit 0x00d7e257 _UIGestureRecognizerUpdate + 13225
23 UIKit 0x0099771b -[UIWindow _sendGesturesForEvent:] + 1356
24 UIKit 0x0099857f -[UIWindow sendEvent:] + 769
25 UIKit 0x0095daa9 -[UIApplication sendEvent:] + 242
26 UIKit 0x0096d8de _UIApplicationHandleEventFromQueueEvent + 20690
27 UIKit 0x00942079 _UIApplicationHandleEventQueue + 2206
28 CoreFoundation 0x03a6d7bf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
29 CoreFoundation 0x03a632cd __CFRunLoopDoSources0 + 253
30 CoreFoundation 0x03a62828 __CFRunLoopRun + 952
31 CoreFoundation 0x03a621ab CFRunLoopRunSpecific + 443
32 CoreFoundation 0x03a61fdb CFRunLoopRunInMode + 123
33 GraphicsServices 0x04b5a24f GSEventRunModal + 192
34 GraphicsServices 0x04b5a08c GSEventRun + 104
35 UIKit 0x00945e16 UIApplicationMain + 1526
36 Ace Metrix MOBILE HD 0x00006cad main + 141
37 libdyld.dylib 0x03541ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I think somewhere you are doing [label length] instead of [label.text length]

UICollectionView registerClass not working in UIViewController (with pics, code, & log)

I have a program that I want to split the screen into two different sections (UISplitViewController is not applicable here because I already have a UINavigationController as the rootMenuController.
The problem is that I can't get my UITableView or my UICollectionView to use the registerClass method. For UITableView it's not a problem, but it's required for the UICollectionView. I ran the simulator to show what it looks like with the UICollectionView disconnected.
What am I doing wrong where it won't register the class for cell reuse identifier>
#import "SELMenuViewController.h"
#interface SELMenuViewController () <UITableViewDataSource, UITableViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate>
#property (weak, nonatomic) IBOutlet UIButton *backButton;
#property (weak, nonatomic) IBOutlet UIButton *paymentButton;
#end
#implementation SELMenuViewController
- (IBAction)employeeSelect:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
self.navigationController.navigationBarHidden = NO;
}
- (IBAction)paymentScreen:(id)sender {
NSLog(#"payment screen");
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection: (NSInteger)section {
return 1;
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"menuCell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor redColor];
return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] init];
cell.textLabel.text = #"text";
return cell;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.itemsOrdered = [[UITableView alloc] init];
self.menuItems = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:[[UICollectionViewFlowLayout alloc] init]];
[self.menuItems registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:#"menuCell"];
}
return self;
}
Here is the error log...
2014-07-29 18:52:40.302 OlymPOS[2267:60b] * Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:], /SourceCache/UIKit_Sim/UIKit-2935.137/UICollectionView.m:3241
2014-07-29 18:52:40.306 OlymPOS[2267:60b] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier menuCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(
0 CoreFoundation 0x00000001019a5495 exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010170499e objc_exception_throw + 43
2 CoreFoundation 0x00000001019a531a +[NSException raise:format:arguments:] + 106
3 Foundation 0x00000001012a0f19 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 189
4 UIKit 0x000000010083e2b7 -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 1324
5 OlymPOS 0x0000000100013efe -[SELMenuViewController collectionView:cellForItemAtIndexPath:] + 110
6 UIKit 0x0000000100831cae -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 264
7 UIKit 0x000000010083330b -[UICollectionView _updateVisibleCellsNow:] + 3581
8 UIKit 0x0000000100836ae1 -[UICollectionView layoutSubviews] + 243
9 UIKit 0x0000000100311993 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354
10 QuartzCore 0x0000000104475802 -[CALayer layoutSublayers] + 151
11 QuartzCore 0x000000010446a369 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
12 QuartzCore 0x000000010446a1ea _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
13 QuartzCore 0x00000001043ddfb8 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 252
14 QuartzCore 0x00000001043df030 _ZN2CA11Transaction6commitEv + 394
15 QuartzCore 0x00000001043df69d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
16 CoreFoundation 0x0000000101970dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23
17 CoreFoundation 0x0000000101970d37 __CFRunLoopDoObservers + 391
18 CoreFoundation 0x0000000101950522 __CFRunLoopRun + 946
19 CoreFoundation 0x000000010194fd83 CFRunLoopRunSpecific + 467
20 GraphicsServices 0x0000000104002f04 GSEventRunModal + 161
21 UIKit 0x00000001002b1e33 UIApplicationMain + 1010
22 OlymPOS 0x000000010000f663 main + 115
23 libdyld.dylib 0x00000001025235fd start + 1
24 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
You create a collection view in init, register your class properly, and set it to your (presumably) outlet.
Then, the view will be loaded, which happens later than init, and this will create another collection view and assign it to the outlet. This collection view hasn't had a class registered, so it fails.
It's not clear why you are bothering making a collection view if there is one in your xib, unless it was a desperate workaround.
The right thing to do is register the class in viewDidLoad, by which point the collection view from the nib will exist.

numberOfRowsInSection is causing unrecognized selector crash

I have a UITableView setup within my view controller to populate with the JSON data that's being returned by a function. When I load MatchCenterViewController, the app crashes and I receive the following error:
2014-06-07 15:56:23.651 Parse+Storyboard[6848:607] -[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xaa29730
2014-06-07 15:56:23.825 Parse+Storyboard[6848:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xaa29730'
*** First throw call stack:
(
0 CoreFoundation 0x02a8c1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0264a8e5 objc_exception_throw + 44
2 CoreFoundation 0x02b29243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x02a7c50b ___forwarding___ + 1019
4 CoreFoundation 0x02a7c0ee _CF_forwarding_prep_0 + 14
5 UIKit 0x0156f94c -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2510
6 UIKit 0x0157323d -[UITableViewRowData numberOfRows] + 98
7 UIKit 0x013f0df2 -[UITableView noteNumberOfRowsChanged] + 120
8 UIKit 0x013f07a5 -[UITableView reloadData] + 814
9 UIKit 0x013f43b3 -[UITableView _reloadDataIfNeeded] + 65
10 UIKit 0x013f95f4 -[UITableView layoutSubviews] + 36
11 UIKit 0x01379964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
12 libobjc.A.dylib 0x0265c82b -[NSObject performSelector:withObject:] + 70
13 QuartzCore 0x0064f45a -[CALayer layoutSublayers] + 148
14 QuartzCore 0x00643244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
15 QuartzCore 0x006430b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
16 QuartzCore 0x005a97fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
17 QuartzCore 0x005aab85 _ZN2CA11Transaction6commitEv + 393
18 QuartzCore 0x006685b0 +[CATransaction flush] + 52
19 UIKit 0x013089bb _UIApplicationHandleEventQueue + 13095
20 CoreFoundation 0x02a1577f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
21 CoreFoundation 0x02a1510b __CFRunLoopDoSources0 + 235
22 CoreFoundation 0x02a321ae __CFRunLoopRun + 910
23 CoreFoundation 0x02a319d3 CFRunLoopRunSpecific + 467
24 CoreFoundation 0x02a317eb CFRunLoopRunInMode + 123
25 GraphicsServices 0x02ce95ee GSEventRunModal + 192
26 GraphicsServices 0x02ce942b GSEventRun + 104
27 UIKit 0x0130af9b UIApplicationMain + 1225
28 Parse+Storyboard 0x00002cbd main + 141
29 libdyld.dylib 0x038e56d9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I've checked UIView tableView:numberOfRowsInSection that the error code refers to, and I don't see what could be causing this, as it simply tells it that there are 3 rows. Code and screenshots are below.
MatchCenterViewController.m:
#import "MatchCenterViewController.h"
#import <UIKit/UIKit.h>
#interface MatchCenterViewController () <UITableViewDataSource, UITableViewDelegate>
#property (weak, nonatomic) IBOutlet UITableView *matchCenter;
#end
#implementation MatchCenterViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *matchCenterDictionary= [self.matchCenterArray objectAtIndex:indexPath.row];
cell.textLabel.text = [matchCenterDictionary objectForKey:#"Title"];// title of the first object
// if([matchCenterDictionary objectForKey:#"Price"] != NULL)
// {
// cell.detailTextLabel.text = [NSString stringWithFormat:#"$%#",[matchCenterDictionary objectForKey:#"Price"]];
// }
return cell;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.matchCenterArray = [[NSArray alloc] init];
//perform search with criteria just submitted
[PFCloud callFunctionInBackground:#"MatchCenterTest"
withParameters:#{
#"test": #"Hi",
}
block:^(NSDictionary *result, NSError *error) {
if (!error) {
self.matchCenterArray = [result objectForKey:#"Top 3"];
dispatch_async(dispatch_get_main_queue(), ^{
[_matchCenter reloadData];
});
NSLog(#"Test Result: '%#'", result);
}
}];
}
- (void)viewDidAppear:(BOOL)animated
{
[PFCloud callFunctionInBackground:#"MatchCenterTest"
withParameters:#{
#"test": #"Hi",
}
block:^(NSDictionary *result, NSError *error) {
if (!error) {
self.matchCenterArray = [result objectForKey:#"Top 3"];
dispatch_async(dispatch_get_main_queue(), ^{
[_matchCenter reloadData];
});
NSLog(#"Test Result: '%#'", result);
}
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
You're setting the UITableViewDelegate and UITableViewDataSource of your tableView to the UIView and not your MatchCenterViewController in interface builder.
UIView doesn't implement UITableViewDataSource and that's why you are getting an unrecognized selector error.
You need to set the delegate and dataSource to the class that implements the delegate methods. In your case, that's your MatchCenterViewController.
Also another thing I notice, you're calling the PFCloud method both on viewDidLoad and viewDidAppear. You should only do that in one place, if you want it to execute one, add it to the viewDidLoad, if you want it to execute every time the view is shown, add it to viewDidAppear.
And another small thing: You should have methods in the order from top to bottom (in your file):
dealloc (if you have one)
initializer methods (init, initWithFrame, etc.)
Other methods, the related ones grouped up, usually separated with #pragma mark.
You need to set MatchCenterViewController class as dataSource and delegate for your matchCenter table view.
Add following 2 lines of code in initWithNibName function
[matchCenter setDelegate:self];
[matchCenter setDataSource:self];

UITableView array returning error 'index 0 beyond bounds for empty array'

I've programmatically created a UITableView within my MatchCenterViewController, however it doesn't seem to populate with the JSON data being returned by my cloud code function. It crashes and gives me the following error:
2014-06-08 20:56:23.762 Parse+Storyboard[9136:607] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
0 CoreFoundation 0x02a8c1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0264a8e5 objc_exception_throw + 44
2 CoreFoundation 0x02a408b2 -[__NSArrayI objectAtIndex:] + 210
3 Parse+Storyboard 0x00005e6a -[MatchCenterViewController tableView:cellForRowAtIndexPath:] + 218
4 UIKit 0x0140311f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
5 UIKit 0x014031f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
6 UIKit 0x013e4ece -[UITableView _updateVisibleCellsNow:] + 2428
7 UIKit 0x013f96a5 -[UITableView layoutSubviews] + 213
8 UIKit 0x01379964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
9 libobjc.A.dylib 0x0265c82b -[NSObject performSelector:withObject:] + 70
10 QuartzCore 0x0064f45a -[CALayer layoutSublayers] + 148
11 QuartzCore 0x00643244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
12 QuartzCore 0x006430b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
13 QuartzCore 0x005a97fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
14 QuartzCore 0x005aab85 _ZN2CA11Transaction6commitEv + 393
15 QuartzCore 0x006685b0 +[CATransaction flush] + 52
16 UIKit 0x013089bb _UIApplicationHandleEventQueue + 13095
17 CoreFoundation 0x02a1577f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
18 CoreFoundation 0x02a1510b __CFRunLoopDoSources0 + 235
19 CoreFoundation 0x02a321ae __CFRunLoopRun + 910
20 CoreFoundation 0x02a319d3 CFRunLoopRunSpecific + 467
21 CoreFoundation 0x02a317eb CFRunLoopRunInMode + 123
22 GraphicsServices 0x02ce95ee GSEventRunModal + 192
23 GraphicsServices 0x02ce942b GSEventRun + 104
24 UIKit 0x0130af9b UIApplicationMain + 1225
25 Parse+Storyboard 0x00002b4d main + 141
26 libdyld.dylib 0x038e56d9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
From what I can understand, it's telling me that self.matchCenterArray is empty, but I can't seem to figure out why the array isn't populating with the JSON being returned.
MatchCenterViewController.h:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "AsyncImageView.h"
#import "SearchViewController.h"
#interface MatchCenterViewController : UIViewController <UITableViewDataSource>
#property (nonatomic) IBOutlet NSString *itemSearch;
#property (nonatomic, strong) NSArray *imageURLs;
#property (strong, nonatomic) NSString *matchingCategoryCondition;
#property (strong, nonatomic) NSString *matchingCategoryLocation;
#property (strong, nonatomic) NSNumber *matchingCategoryMaxPrice;
#property (strong, nonatomic) NSNumber *matchingCategoryMinPrice;
#property (strong, nonatomic) NSArray *matchCenterArray;
#end
MatchCenterViewController.m:
#import "MatchCenterViewController.h"
#import <UIKit/UIKit.h>
#interface MatchCenterViewController () <UITableViewDataSource, UITableViewDelegate>
#property (nonatomic, strong) UITableView *matchCenter;
#end
#implementation MatchCenterViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// self.matchCenter = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
// _matchCenter.dataSource = self;
// _matchCenter.delegate = self;
// [self.view addSubview:self.matchCenter];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.matchCenter registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
self.matchCenter = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
_matchCenter.dataSource = self;
_matchCenter.delegate = self;
[self.view addSubview:self.matchCenter];
self.matchCenterArray = [[NSArray alloc] init];
}
- (void)viewDidAppear:(BOOL)animated
{
self.matchCenterArray = [[NSArray alloc] init];
[PFCloud callFunctionInBackground:#"MatchCenterTest"
withParameters:#{
#"test": #"Hi",
}
block:^(NSDictionary *result, NSError *error) {
if (!error) {
self.matchCenterArray = [result objectForKey:#"Top 3"];
dispatch_async(dispatch_get_main_queue(), ^{
[_matchCenter reloadData];
});
NSLog(#"Test Result: '%#'", result);
}
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *matchCenterDictionary= [self.matchCenterArray objectAtIndex:indexPath.row];
cell.textLabel.text = [matchCenterDictionary objectForKey:#"Title"];// title of the first object
// if([matchCenterDictionary objectForKey:#"Price"] != NULL)
// {
// cell.detailTextLabel.text = [NSString stringWithFormat:#"$%#",[matchCenterDictionary objectForKey:#"Price"]];
// }
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
JSON that's returned:
{
"Top 3" : [
{
"Title" : "Apple iPhone 5s (Latest Model) - 16GB - Silver (AT&T) Smartphone",
"Price" : "400.0",
"Image URL" : "http://thumbs2.ebaystatic.com/m/mewfVG0QbBiu1nZytMuAlZw/140.jpg",
"Item URL" : "http://www.ebay.com/itm/Apple-iPhone-5s-Latest-Model-16GB-Silver-AT-T-Smartphone-/181431570117?pt:Cell_Phones"
},
{
"Title" : "Apple iPhone 5c (Latest Model) - 16GB - Pink (Verizon) Smartphone",
"Price" : "350.0",
"Image URL" : "http://thumbs4.ebaystatic.com/m/mMPAT67KjfCZF9oorbTf3uw/140.jpg",
"Item URL" : "http://www.ebay.com/itm/Apple-iPhone-5c-Latest-Model-16GB-Pink-Verizon-Smartphone-/191204844039?pt:Cell_Phones"
},
{
"Title" : "Apple iPhone 5 16GB, White, works with Virgin Mobile US NEW",
"Price" : "359.99",
"Image URL" : "http://thumbs3.ebaystatic.com/m/m5x1uj1iSS2fr691tifrvrw/140.jpg",
"Item URL" : "http://www.ebay.com/itm/Apple-iPhone-5-16GB-White-works-Virgin-Mobile-US-NEW-/141227441998?pt:Cell_Phones"
}
]
}
UITableView will request cells before your API call has returned data. Network request can take a long time, and if the user is not connected to the network it will fail completely. Don't assume that your network calls will return immediately.
And because you start your asynchronous (!) API call only in viewDidAppear: the tableView starts to request cells even before you have started the API call.
Since you have specified that there are 3 rows in your first section tableView:cellForRowAtIndexPath: tries to access this:
// for first row
NSDictionary *matchCenterDictionary= [self.matchCenterArray objectAtIndex:0];
Which raises an out of bounds exception because your array is empty, and does not have an object at index 0.
Don't return 3 in tableView:numberOfRowsInSection: if you don't have 3 objects in your array, return the actual number of objects that are contained in your array:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.matchCenterArray count];
}
and to prevent your next crash, move the call where you register the cell to a place where self.matchCenter is not nil, i.e. after the alloc init of the tableView.
e.g.:
self.matchCenter = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
/* ... */
[self.matchCenter registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];

iOS Slide out menu is causing app to crash. How to fix?

I am creating an rss feed app with a slide out navigation bar as shown here(http://www.appcoda.com/ios-programming-sidebar-navigation-menu/).
The app will load and RSS feeds will parse and appear on my main screen. You can click on a feed and it will lead to a webView to show that corresponding website. I will also have a navigation bar button on the top left to toggle the slide out menu. I am not able to proceed working on my app because it keeps crashing.BTW, I'm using a third party library called SWRevealViewController.Here is my MasterViewController:
//
// JSSMasterViewController.m
// News App
//
// Created by Steve on 4/5/14.
// Copyright (c) 2014 self.edu.steve. All rights reserved.
//
#import "JSSMasterViewController.h"
#import "JSSDetailViewController.h"
#import "SWRevealViewController.h"
#interface JSSMasterViewController () {
NSXMLParser *parser;
NSMutableArray *feeds;
NSMutableDictionary *item;
NSMutableString *title;
NSMutableString *link;
NSString *element;
}
#end
#implementation JSSMasterViewController
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
feeds = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:#"http://images.apple.com/main/rss/hotnews/hotnews.rss"];
parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
// Change button color
_sidebarButton.tintColor = [UIColor colorWithWhite:0.96f alpha:0.2f];
// Set the side bar button action. When it's tapped, it'll show up the sidebar.
_sidebarButton.target = self.revealViewController;
_sidebarButton.action = #selector(revealToggle:);
// Set the gesture
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return feeds.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
cell.textLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: #"title"];
return cell;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
element = elementName;
if ([element isEqualToString:#"item"]) {
item = [[NSMutableDictionary alloc] init];
title = [[NSMutableString alloc] init];
link = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:#"item"]) {
[item setObject:title forKey:#"title"];
[item setObject:link forKey:#"link"];
[feeds addObject:[item copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([element isEqualToString:#"title"]) {
[title appendString:string];
} else if ([element isEqualToString:#"link"]) {
[link appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[self.tableView reloadData];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *string = [feeds[indexPath.row] objectForKey: #"link"];
[[segue destinationViewController] setUrl:string];
}
}
#end
Here is SideBar View controller that manages the Slide out menu:
//
// JSSSidebarViewController.m
// News App
//
// Created by Steve on 4/5/14.
// Copyright (c) 2014 self.edu.steve. All rights reserved.
//
#import "JSSSidebarViewController.h"
#import "SWRevealViewController.h"
#interface JSSSidebarViewController ()
#end
#implementation JSSSidebarViewController{
NSArray *menuItems;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
menuItems = #[#"title", #"news", #"comments", #"map", #"calendar", #"wishlist", #"bookmark", #"tag"];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [menuItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
return cell;
}
- (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
{
// Set the title of navigation bar by using the menu items
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UINavigationController *destViewController = (UINavigationController*)segue.destinationViewController;
destViewController.title = [[menuItems objectAtIndex:indexPath.row] capitalizedString];
// Set the photo if it navigates to the PhotoView
if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] ) {
SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;
swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {
UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
[navController setViewControllers: #[dvc] animated: NO ];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
};
}
}
#end
I am not able to find out the solution. Here is my logs:
2014-04-05 20:17:43.843 News App[4496:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101968495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001016c799e objc_exception_throw + 43
2 CoreFoundation 0x000000010191f374 -[__NSArrayM insertObject:atIndex:] + 820
3 UIKit 0x00000001002d40da -[UIView(UIViewGestures) addGestureRecognizer:] + 199
4 News App 0x0000000100001ecf -[JSSMasterViewController viewDidLoad] + 719
5 UIKit 0x000000010036a59e -[UIViewController loadViewIfRequired] + 562
6 UIKit 0x000000010036a777 -[UIViewController view] + 29
7 UIKit 0x00000001006752e2 -[UIClientRotationContext initWithClient:toOrientation:duration:andWindow:] + 390
8 UIKit 0x00000001002b0ffa -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 1109
9 UIKit 0x00000001002b0b9f -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 36
10 UIKit 0x00000001002b0aef -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 101
11 UIKit 0x00000001002afdfe -[UIWindow _updateToInterfaceOrientation:duration:force:] + 377
12 UIKit 0x000000010036e70a -[UIViewController _tryBecomeRootViewControllerInWindow:] + 147
13 UIKit 0x00000001002aab1b -[UIWindow addRootViewControllerViewIfPossible] + 490
14 UIKit 0x00000001002aac70 -[UIWindow _setHidden:forced:] + 282
15 UIKit 0x00000001002b3ffa -[UIWindow makeKeyAndVisible] + 51
16 UIKit 0x000000010026fc98 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1788
17 UIKit 0x0000000100273a0c -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 660
18 UIKit 0x0000000100284d4c -[UIApplication handleEvent:withNewEvent:] + 3189
19 UIKit 0x0000000100285216 -[UIApplication sendEvent:] + 79
20 UIKit 0x0000000100275086 _UIApplicationHandleEvent + 578
21 GraphicsServices 0x0000000103ae171a _PurpleEventCallback + 762
22 GraphicsServices 0x0000000103ae11e1 PurpleEventCallback + 35
23 CoreFoundation 0x00000001018ea679 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
24 CoreFoundation 0x00000001018ea44e __CFRunLoopDoSource1 + 478
25 CoreFoundation 0x0000000101913903 __CFRunLoopRun + 1939
26 CoreFoundation 0x0000000101912d83 CFRunLoopRunSpecific + 467
27 UIKit 0x00000001002732e1 -[UIApplication _run] + 609
28 UIKit 0x0000000100274e33 UIApplicationMain + 1010
29 News App 0x0000000100002c23 main + 115
30 libdyld.dylib 0x00000001020005fd start + 1
31 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Thank you for any Help!
The error is exactly what your error log says:
'*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
You are trying to insert an object to an array and that object is nil. In this particular case, it's this line that's causing problem:
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
You will need to alloc self.revealViewController.panGestureRecognizer first before adding it as the view's gesture recognizers.
One way to alloc the gesture recognizer:
UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(someMethod:)];
[self.view addGestureRecognizer:gestureRecognizer];

Resources