Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-01-2012, 08:23 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 3
St@n is on a distinguished road
Default NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

Can someone help to check my code? i can't seem to find the out of bounds part



- (void)viewDidLoad
{
[super viewDidLoad];
sectionsArray = [[NSArray alloc] initWithObjects:[[NSNumber alloc]initWithInt:4],[[NSNumber alloc]initWithInt:2], nil];

self.title = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleName"];
menuList = [[NSMutableArray alloc]init];

[menuList addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"Keywords", @"Keywords Section"),kSelectKey,NSLocalizedString(@"Words to identify pattern", @"Words to identify pattern Explain"),kDescriptKey,nil,kControllerKey,nil]];


menuList = [[NSMutableArray alloc]init];
[menuList addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"Twitter Feed", @"Twitter Section"),kSelectKey,NSLocalizedString(@"Twitter", @"Twitter Explain"),kDescriptKey,nil,kControllerKey,nil]];

menuList = [[NSMutableArray alloc]init];
[menuList addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"Product Review", @"Product Review Section"),kSelectKey,NSLocalizedString(@"Sentiment s of Product", @"Sentiments of Product Explain"),kDescriptKey,nil,kControllerKey,nil]];

menuList = [[NSMutableArray alloc]init];
[menuList addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"Graphs", @"Keywords Section"),kSelectKey,NSLocalizedString(@"Analysis" , @"Analysis Explain"),kDescriptKey,nil,kControllerKey,nil]];

menuList = [[NSMutableArray alloc]init];
[menuList addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"Hotels", @"Hotels Section"),kSelectKey,NSLocalizedString(@"Nearby Hotels", @"Nearby Hotels Explain"),kDescriptKey,nil,kControllerKey,nil]];




}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath
{
// static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
CGRect subViewFrame = cell.contentView.frame;
subViewFrame.origin.x += kInset;
subViewFrame.size.width = kInset+kSelectLabelWidth;

UILabel *selectLabel = [[UILabel alloc]initWithFrame:subViewFrame];

selectLabel.textColor = [UIColor blackColor];
selectLabel.highlightedTextColor=[UIColor whiteColor];
selectLabel.font = [ UIFont boldSystemFontOfSize:18];
selectLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:selectLabel];

subViewFrame.origin.x +=kInset+kSelectLabelWidth;
subViewFrame.size.width = kDescriptLabelWidth;
UILabel *descriptLabel = [[UILabel alloc]initWithFrame:subViewFrame];
descriptLabel.textColor = [UIColor grayColor];
descriptLabel.highlightedTextColor=[UIColor whiteColor];
descriptLabel.font = [UIFont systemFontOfSize:14];
descriptLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:descriptLabel];

int menuOffset = (indexPath.section*kSection1Rows)+ indexPath.row;

NSDictionary *cellText = [menuList objectAtIndex:menuOffset];
selectLabel.text = [cellText objectForKey:kSelectKey];
descriptLabel.text=[cellText objectForKey:kDescriptKey];
[selectLabel release];
[descriptLabel release];
}
St@n is offline   Reply With Quote
Old 02-01-2012, 08:25 AM   #2 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

You re-assign menuList every time you add new items. Don't do that.
harrytheshark is offline   Reply With Quote
Old 02-01-2012, 09:04 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 3
St@n is on a distinguished road
Default

Quote:
Originally Posted by harrytheshark View Post
You re-assign menuList every time you add new items. Don't do that.
Then How do you suggest i do?

I was following instructions from a Dummy guide.
St@n is offline   Reply With Quote
Old 02-01-2012, 09:35 AM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by St@n View Post
Then How do you suggest i do?

I was following instructions from a Dummy guide.

Translation:

"I am copy-and-pasting code from a guide without any understanding of what I'm doing. Can you fix my code for me?"


In your viewDidLoad, get rid of every call to


Code:
menuList = [[NSMutableArray alloc]init];
...except the first.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 02-01-2012, 10:01 AM   #5 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 3
St@n is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Translation:

"I am copy-and-pasting code from a guide without any understanding of what I'm doing. Can you fix my code for me?"


In your viewDidLoad, get rid of every call to


Code:
menuList = [[NSMutableArray alloc]init];
...except the first.
Thanks for the tip. Well we all got to start from somewhere and i think learning from our mistakes is the way forward.

Thank you once again for your help Duncan. Cheers!
St@n is offline   Reply With Quote
Reply

Bookmarks

Tags
nsmutablearray mail, xcode

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 418
17 members and 401 guests
Atatator, chiataytuday, condor304, dre, FrankWeller, imac74, ipodphone, jeroenkeij, kukat, LunarMoon, MAMN84, n00b, PowerGoofy, QuantumDoja, Retouchable, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,675
Threads: 94,124
Posts: 402,909
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Retouchable
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:02 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0