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-29-2010, 04:32 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 25
drnkHobo is on a distinguished road
Exclamation Sharing Array between Views

Hi there all,
ive been stuck with this problem for a couple of days now and cant seem to get anywhere.

Basically I want to copy dictionaries between views.
In one view I have a table with some data.Its using a plist, with an array of dictionaries.
In the other view, once again a table but I want to be able to fill this table with a user selection of dictionaries from the first view.

This is how i have set it up:

I have 3 viewControllers:

1stTableViewController--------main table view with all data

2ndTableViewController-------user selected table view

DetailViewController-----------show the details of selected row


So in the detailview I have made a button to "watch" a entry.
What I mean is like in the ebay app, you can select items to put in your watch list.

Inside my button pressed method i have done this:

Code:
- (IBAction)watchButtonPressed:(id)sender {UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Watch?"	message:@"You wanna watch?" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];[alert show];

// Retrieve Selected rows data from 1stVC
    NSString *publisher = [book objectForKey:PUB_KEY];
    NSString *name = [book objectForKey: NAME_KEY];
    NSString *description =	[book objectForKey: INFO_KEY];
		
	NSString *errorDesc;
	
	//Creating a delegate so I can access the mutable dictionary data
	myAppDelegate *delegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate];
	

	
	NSDictionary *plistDict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: name, publisher, description, nil] forKeys:[NSArray arrayWithObjects:@"Name", @"Publisher", @"Description", nil]];
	NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:plistDict format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];
	
	//Adding plistDict to data Dictionary
	[delegate.data addObject:plistData];

now that finds the data corresponding to the selected row.Creates a dict with that data and then adds it to an array in my appDelegate called "data".
well, at least i think it should.

In my 2ndTable VC i have this :

Code:
myAppDelegate *delegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate];
	
	myBooks = delegate.data;
myBooks is an array which will feed the table view.

Now when I try run this in the simulator it doesnt pass the data.

Can anyone help me with this?

Is my method of passing data thru the appDelegate right?
Can I do this?
drnkHobo is offline   Reply With Quote
Old 07-29-2010, 04:38 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

now that finds the data corresponding to the selected row.Creates a dict with that data and then adds it to an array in my appDelegate called "data".
well, at least i think it should.

If you wanna check stuff like that, use this:

Code:
NSLog(@"Data: %@", data);
This way you can see what is and what is not being 'transferred'.
rickrets is offline   Reply With Quote
Old 07-29-2010, 04:55 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 25
drnkHobo is on a distinguished road
Default

Quote:
Originally Posted by rickrets View Post
now that finds the data corresponding to the selected row.Creates a dict with that data and then adds it to an array in my appDelegate called "data".
well, at least i think it should.

If you wanna check stuff like that, use this:

Code:
NSLog(@"Data: %@", data);
This way you can see what is and what is not being 'transferred'.
Thanks rickrets, ive put that code into my appDelegate but to no avail!
i get no logs or anything?
drnkHobo is offline   Reply With Quote
Old 07-29-2010, 04:59 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

Put it where you want to achieve the information.
You did check it in the Console (run -> console), right?
rickrets is offline   Reply With Quote
Old 07-29-2010, 05:03 AM   #5 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 25
drnkHobo is on a distinguished road
Default

Quote:
Originally Posted by rickrets View Post
Put it where you want to achieve the information.
You did check it in the Console (run -> console), right?
yep, i put it in my aplicationDidFinishLaunching.
and nothing in the console...?


****wait wait, got it!!!

heh heh heh, but Data:null.

its not writing the dictionary

Last edited by drnkHobo; 07-29-2010 at 05:09 AM.
drnkHobo is offline   Reply With Quote
Old 07-29-2010, 05:08 AM   #6 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

You need to put it in one of the view controllers you created.

i.e. in 2ndTable.

Try something like:

NSLog(@"Data: %@", delegate.data)

If you see in the console:

Data:

Then it is indeed empty, then try to log it in a way untill you get something
rickrets is offline   Reply With Quote
Old 07-29-2010, 05:25 AM   #7 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 25
drnkHobo is on a distinguished road
Default

Right so ive checked with NSLog and it creates the dictionary fine except when i use log on delegate.data it shows null.
Which means either im not adding the object correctly or my method of using the appDelegate is incorrect. . . .
drnkHobo is offline   Reply With Quote
Old 07-29-2010, 05:30 AM   #8 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

You are doing this:

[delegate.data addObjectlistData];

Check after that with a log if the plisData is in there, if it is, it narrows the problem down to "using the appDelegate is incorrect. . . . "

But I never used appDelegate, so I can't help you with that!
rickrets is offline   Reply With Quote
Old 07-29-2010, 05:32 AM   #9 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 25
drnkHobo is on a distinguished road
Default

Quote:
Originally Posted by rickrets View Post
You are doing this:

[delegate.data addObjectlistData];

Check after that with a log if the plisData is in there, if it is, it narrows the problem down to "using the appDelegate is incorrect. . . . "

But I never used appDelegate, so I can't help you with that!
Thanks, I am logging after and still null....

need to do more searching on appDelegate methods
drnkHobo is offline   Reply With Quote
Old 07-29-2010, 09:13 AM   #10 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 25
drnkHobo is on a distinguished road
Default

Ok, so ive got it working, partially....

Ive created an array in 2ndViewController and added the object from delegate.data like this:
Code:
 [tempArray addObject:delegate.data];
so now i goto 1stVC, select a book. Inside detail view push watch button,go back to 2ndVC which is "MybooksTable View" and there is the book i selected to watch! however, if i go back and try to "add" more books to watch it still only displays the first book I selected to watch. . .

i have got
Code:
[self.tableView reloadData];
still only the first book???

Anyone out there with some help for me?
drnkHobo is offline   Reply With Quote
Reply

Bookmarks

Tags
dictionary, plist

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: 341
17 members and 324 guests
appservice, bignoggins, dermotos, Domele, EXOPTENDAELAX, guusleijsten, Hamad, heshiming, linkmx, mariano_donati, Objective Zero, ohmniac, 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:47 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0