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 07-30-2010, 02:27 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 25
drnkHobo is on a distinguished road
Default NSMutableArray not responding to addObject:

Hey guys, a mutable array in my app is not accepting objects from another class.

Basically I add a NSMutableDictionary in one view to an NSMutableDictionary assigned in my app Delegate and pass the data to another view, in which I want to populate my table view.

So the variable in my app delegate holds the dictionary selected in the first view.Ive got his verified with NSLog.

In my table view (second view) the app delegate has data.
Then my code to add dictionary from app delegate to NSMutableArray in table view and NSMutableArray = null. . . .

Can someone look at my code and point me in the right direction???

Here is where I set the Dictionary in the first view:

Code:
 NSString *publisher = [book	objectForKey:PUB_KEY];
    NSString *name = [book objectForKey: NAME_KEY];
    NSString *description =	[book objectForKey: INFO_KEY];

	//Creating a delegate so I can access the mutable dictionary data
	TESTAppDelegate *delegate = (TESTAppDelegate *)[[UIApplication sharedApplication] delegate];
	
	NSMutableDictionary *plistDict = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects: name, publisher, description, nil] forKeys:[NSArray arrayWithObjects:@"Name", @"Publisher", @"Description", nil]];
	
	//Adding plistDict to data Dictionary
        delegate.data = plistDict;
	NSLog(@"delegate.data In First View: %@",delegate.data);
So that adds the dictionary created into delegate.data---the NSMutableDictionary in app Delegate.

Now my table view:

Code:
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
	
	TESTAppDelegate *delegate = (TESTAppDelegate *)[[UIApplication sharedApplication] delegate];
			
	        [tempArray init];
		[tempArray addObject:delegate.data ];
		NSLog(@"tempARRAY in tableview: %@",tempArray);
		
			NSLog(@"delegate.data: %@",delegate.data);	

	self.myBooks = tempArray;
	
	[self.tableView reloadData];
}
So here when the view loads every time, I init a array: tempArray, and add delegate.data to it.Then "myBooks" Mutable Array = tempArray.Which I then use to fill my tableview , cell, ect with.

now the logs say that delegate.data in the tableview IS the saved dictionary assigned in first view.But tempArray = null....


Any help or push in the right direction?
drnkHobo is offline   Reply With Quote
Old 07-30-2010, 02:47 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

You can't just init, you have to alloc first.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-30-2010, 03:07 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 25
drnkHobo is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
You can't just init, you have to alloc first.
but ive created them in my .h file as NSMutableArray with property and @synthesize'd them in the .m


It tells me it may not respond to -alloc. . . .
drnkHobo is offline   Reply With Quote
Old 07-30-2010, 03:08 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

And now you need to go read the properties link in my signature.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-31-2010, 05:19 AM   #5 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Quote:
Originally Posted by drnkHobo View Post
but ive created them in my .h file as NSMutableArray with property and @synthesize'd them in the .m


It tells me it may not respond to -alloc. . . .
Dear lord...
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 08-01-2010, 11:46 AM   #6 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 25
drnkHobo is on a distinguished road
Default

Thanks brainslick.
I was just reading it nice one.

Ive hit another problem in my app and if anyone can help me it would be appreciated.In this code:

Code:
        
        NSMutableArray *tmpArray = [[NSMutableArray alloc] init];
        NSDictionary *tempDict = [[NSDictionary alloc] init];
        
        tempDict = delegate.data; //delegate.data is a dictionary
        
        [tmpArray addObject:tempDict];
       
        self.muckArray = tmpArray;
                                       
                                        NSLog(@"tmpArray  %@",tmpArray);
                                        NSLog(@"delegate.data  %@",delegate.data);    
    
    self.myBooks = self.muckArray;
        
        
    [self.tableView reloadData];
So im using myBooks to fill my table with.
Now ive gotten it to add the selected dictionary to the myBooks array and it works fine but whenever I go select another dictionary to add it replaces the whole array.
It just overwrites the first entry?
I know its the way im doing it but I just cant see where im going wrong.nor do I have the experience.

Anyone please help.
drnkHobo is offline   Reply With Quote
Old 08-01-2010, 11:50 AM   #7 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Well, walk through your code, figure out what you are doing, and how that compares with what your desired end result is.

You are leaking the first tempDict, by the way.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 08-01-2010, 12:12 PM   #8 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 25
drnkHobo is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Well, walk through your code, figure out what you are doing, and how that compares with what your desired end result is.

You are leaking the first tempDict, by the way.

well, ive figured that im just making a pointer to the dictionary.
I need to save the array I create with the dictionary..

still thinking, but thanks
drnkHobo is offline   Reply With Quote
Old 08-02-2010, 11:23 AM   #9 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 25
drnkHobo is on a distinguished road
Default

I just cant think of a way to get this to work.
delegate.data (dictionary) is just one object that gets replaced.
I thought that when I use addObject: it wud add and retain that data.
Then just a matter of adding other dictionaries. . . but no joy here

Anyone have any help for me?

thanks

oh, and can all this be done in a much simpler approach with SQLite? ive a stinking feeling it can

Last edited by drnkHobo; 08-02-2010 at 01:11 PM.
drnkHobo is offline   Reply With Quote
Reply

Bookmarks

Tags
app delegate, array, copy, dictionary

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: 335
15 members and 320 guests
appservice, bignoggins, dermotos, Domele, EXOPTENDAELAX, guusleijsten, Hamad, heshiming, linkmx, Objective Zero, Paul Slocum, Rudy, Sloshmonster, teebee74
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

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