01-23-2012, 11:34 PM
#1 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 920
Beyond bounds for empty array
I am trying to implement an inbox for rich notifications with xtify to my tab bar app. The code they use in example I adapted for my use to this:
Code:
- (UINavigationController *) setupPortraitUserInterface
{
UIWindow *localPortraitWindow;
localPortraitWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.portraitWindow = localPortraitWindow;
[localPortraitWindow release];
[portraitWindow setBackgroundColor:[UIColor whiteColor]];
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate = self;
localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:5];
UIViewController *inboxVC=[[XLappMgr get ]getInboxViewController];
UIImage* iImage = [UIImage imageNamed:@"inbox.png"];
inboxVC.tabBarItem.image = iImage;
inboxNavController = [[UINavigationController alloc] initWithRootViewController:inboxVC];
[localViewControllersArray insertObject:inboxNavController atIndex:1];
[localViewControllersArray insertObject:thirdView atIndex:2];
[localViewControllersArray insertObject:firstView atIndex:0];
[localViewControllersArray insertObject:fourthView atIndex:3];
[localViewControllersArray insertObject:fifthView atIndex:4];
firstView= [[FirstViewController alloc] init];
thirdView= [[ThirdViewController alloc] init];
fourthView= [[FourthViewController alloc] init];
fifthView= [[FifthViewController alloc] init];
tabBarController.viewControllers = localViewControllersArray;
[localViewControllersArray release];
[portraitWindow addSubview:tabBarController.view];
[portraitWindow makeKeyAndVisible];
return inboxNavController;
}
I get the error
Code:
[__NSArrayM insertObject:atIndex:]: index 1 beyond bounds for empty array'
Why is the array empty?
01-23-2012, 11:38 PM
#2 (permalink )
Just helping out.
Join Date: Feb 2011
Posts: 2,565
Because you haven't added anything to it yet?
Instead of specifying an index, just add them in order like this:
Code:
[localViewControllersArray addObject:firstView];
[localViewControllersArray addObject:inboxNavController];
//etc..
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.
New app - See screenshots and details at
www.globaclock.com .
If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
01-23-2012, 11:55 PM
#3 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 920
[quote=Domele;403920]Because you haven't added anything to it yet?
Instead of specifying an index, just add them in order like this:
Code:
inboxNavController = [[UINavigationController alloc] initWithRootViewController:inboxVC];
[localViewControllersArray addObject:inboxNavController];
[localViewControllersArray addObject:firstView];
[localViewControllersArray addObject:thirdView];
[localViewControllersArray addObject:fourthView];
[localViewControllersArray addObject:fifthView];
It now gives me the insertObject:atIndex cannot be set to nil. Nowhere in the whole file does it even have the code for insertObject:atIndex.
01-23-2012, 11:57 PM
#4 (permalink )
Just helping out.
Join Date: Feb 2011
Posts: 2,565
Try cleaning, deleting the app, and rebuilding.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.
New app - See screenshots and details at
www.globaclock.com .
If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
01-24-2012, 12:02 AM
#5 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 920
Quote:
Originally Posted by
Domele
Try cleaning, deleting the app, and rebuilding.
Same Issue
Code:
'*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
01-24-2012, 12:13 AM
#6 (permalink )
Just helping out.
Join Date: Feb 2011
Posts: 2,565
You need to allocate your controllers before you add them to the array.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.
New app - See screenshots and details at
www.globaclock.com .
If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
01-24-2012, 12:16 AM
#7 (permalink )
Registered Member
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
You need to initialize firstView,thirdView, fourthView, fifthView before you add them to the array.
Code:
[firstView= [[FirstViewController alloc] init];
thirdView= [[ThirdViewController alloc] init];
fourthView= [[FourthViewController alloc] init];
fifthView= [[FifthViewController alloc] init];
inboxNavController = [[UINavigationController alloc] initWithRootViewController:inboxVC];
[localViewControllersArray addObject:inboxNavController];
[localViewControllersArray addObject:firstView];
[localViewControllersArray addObject:thirdView];
[localViewControllersArray addObject:fourthView];
[localViewControllersArray addObject:fifthView];
__________________
SQLed - Your Database Manager on the go
iAZConverter - Converts everything from A to Z
01-24-2012, 12:29 AM
#8 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 920
Quote:
Originally Posted by
apatsufas
You need to initialize firstView,thirdView, fourthView, fifthView before you add them to the array.
Code:
[firstView= [[FirstViewController alloc] init];
thirdView= [[ThirdViewController alloc] init];
fourthView= [[FourthViewController alloc] init];
fifthView= [[FifthViewController alloc] init];
inboxNavController = [[UINavigationController alloc] initWithRootViewController:inboxVC];
[localViewControllersArray addObject:inboxNavController];
[localViewControllersArray addObject:firstView];
[localViewControllersArray addObject:thirdView];
[localViewControllersArray addObject:fourthView];
[localViewControllersArray addObject:fifthView];
Thanks to you both, that did it
01-24-2012, 01:46 PM
#9 (permalink )
Registered Member
Join Date: Nov 2009
Posts: 920
Well, I thought that fixed the problem. The app will run without terminating or giving errors, but it is just one big white screen, no tab bar controller or anything else.
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 395
11 members and 384 guests
7twenty7 , Atatator , condor304 , FrankWeller , glenn_sayers , iphonedevshani , MAMN84 , mraalex , QuantumDoja , tim0504 , VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator