Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 10    Views: 68

ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
04/11/14 09:10 AM (10 years ago)

using ParentScreenData to populate JSON?

I'm looking to utilize this BT technique to populate some JSON values for a plugin that calls another viewcontroller. Essentially "view A" calls "view B" and I'd like to use some JSON values for properties in "view B" that you populate on "view a" control panel screen. I've looked at the MenuButtons and Blogpro code and even some of the older headerimage code for menu simple for some hints on how others have done this. I'm getting confused with the differences between theParentScreenData, theParentMenuScreenData and theMenuItemdata. If I'm not using a menu or child items in "view A"- Would I just use "theParentScreenData" in "view B" and populate the JSON for "view B" by entering values in "view A" control panel screen. and then I would access these JSON values in "view B" by using something like: [BT_strings getJsonPropertyValue:theParentScreenData.jsonVars nameOfProperty:@"MyCoolJSONValue" defaultvalue:@"mysound.mp3"]; Is this the basics of this, Or am I totally out in left field understanding how this whole ParentScreenData can be utilized to populate JSON for views that call other views?
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
04/11/14 10:12 AM (10 years ago)
Haven't tested this, but it should work. -(BT_item*)getParentScreenData { BT_navController *navController = (BT_navController*)self.navigationController; NSArray *viewControllers = [navController viewControllers]; BT_viewController *parentVC = [viewControllers objectAtIndex:[viewControllers count]-2]; BT_item *parentScreenData = parentVC.screenData; return parentScreenData; }
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
04/11/14 10:13 AM (10 years ago)
Look at handleTapToLoadScreen ... In BuzzTouch V3, it was reduced down to only two parameters. Not near a Mac to take a look at which one got thrown out. Are you building the JSON for View B on the fly? Or is it already in the Control Panel, which means it is already on the device as a cached file? Your basic premise is good. Just a matter of if the BuzzTouch v3 API supports it. Alternatively, when in View B, use NSUserDefaults to indicate which Screen ID's JSON data is to be used. Remember to reset (nil) the property at the end of View B's usage. Let us know what you figured out! :-) Or just listen to Chris ... Hahahah (he posted same time as me)
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
04/11/14 12:10 PM (10 years ago)
Thanks for the help. That looks interesting and a quick clean way to pull this off. I explored the idea of trying to do this with a singleton to pass an object, but it seems like there is a BT way to do this folks are already utilizing. It seems like the menu buttons and some of PSMDannys plugin code is doing this, but trying to reverse engineer it is tricky. Are you saying I should just be able to add that method you posted into "view B" and then I'll be able to access the JSON I entered in 'view a' because your method is setting the parentScreenData as the previous viewcontroller in the stack? I don't need to declare any properties or values?
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
04/11/14 12:11 PM (10 years ago)
yep - you got it exactly.
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
04/11/14 12:58 PM (10 years ago)
Thanks again- Your method compiles without any issues. But if I try to use this line to access the JSONValue [BT_strings getJsonPropertyValue:theParentScreenData.jsonVars nameOfProperty:@"MyCoolJSONValue" defaultvalue:@"mysound.mp3"]; I'm getting use of undeclared identifier errors. If I set BT_item *theparentScreenData and @Property (nonatomic, retain) BT_item *theparentScreenData and synthesize it in the method, that resolves the undeclared identifier errors. but the code doesn't seem to be using the JSON I'm entering in the Control panel, it's just using my hard coded default value. It seems like this has been a reason almost all BT plugins are contained in a single class file to deal with the JSON. The bt_screen_menuButtons looks to have a great working example of this concept in action, but I'm not quite understanding exactly how David uses that *buttonItemData
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
04/11/14 01:36 PM (10 years ago)
Are you using tabs in your app? If so, you may need to get ahold of the navigation controller like so: BT_navController * navController = (BT_navController *)[appDelegate.rootApp.rootTabBarController selectedViewController];
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
04/11/14 01:57 PM (10 years ago)
No Tabs in the app.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
04/11/14 02:08 PM (10 years ago)
That's strange - it works great for me. Here's what I did - I put this in the viewDidAppear method of a plugin that is called from another: BT_item *parentScreen = [self getParentScreenData]; NSLog(@"\n\n\n\n\n\nparentScreen:%@", parentScreen.jsonVars);
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
04/13/14 09:03 AM (10 years ago)
Thanks again, still no dice here. That outputs this to my console: parentScreen:(null) I'd love to get this working because it seems like a much cleaner way to do this than how I see it elsewhere in the BT code. I zipped up the code and sent it your way if you have time to look at it and see what I'm missing. Hoping it's something simple...
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
04/26/14 03:11 PM (10 years ago)
Just a follow up that I came up with another method to access the ParentScreenData. If I Import the app delegate into the class- This will spit out my ParentScreenData instead of (null) now. NSLog(@"\n\n\n\n\n\nparentScreen:%@", appDelegate.rootApp.currentScreenData.jsonVars); Now I can populate and access the JSON. So disregard that email I sent, I'm all set.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.