Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 17    Views: 113

Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
03/07/13 12:00 AM (11 years ago)

How to pass tapped menu item to next screen?

I have a list of fruits as a menu table: - Apple - Apricot - Banana - Cherry - Orange A tap on any of the fruit menu items will show the same email screen, with one small difference from tap to tap: the "To" field accordingly changes. A tap on Apple will cause the "To" field of the email to be filled with "[email protected]". A tap on Cherry will send an email to "[email protected]" From the current menu screen, How do I pass the value of the tapped menu item over to the next screen (email)? Thank you! -- Niraj Shah
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
03/07/13 02:09 AM (11 years ago)
Wouldn't you just put the email address in the email plugin control panel screen.
 
Rishav
Code is Art
Profile
Posts: 153
Reg: Jan 26, 2012
Dubai
8,780
like
03/07/13 04:35 AM (11 years ago)
if you are creating menu items through some code then i suppose using loadScreenObject will be better. You could use variable value to print the fruit names again dataurl's value for launch native app plugin. or you may save the fruit name in the phone using sharedpreference for android and then retrive the value in the next scree.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/07/13 06:14 AM (11 years ago)
Kittsy is right- the way plugins normally work is you don't pass data between them. You simply tell your plugin to load a specific instance of another plugin. Rishav's suggestion is ideal for creating those instances on the fly though. If you really needed to pass a variable to another plugin in the true sense, you would have to modify both to handle it, which would get a little complicated. But I don't see why you would need to do that.
 
GilbertAZ
Aspiring developer
Profile
Posts: 37
Reg: Jul 16, 2012
Arizona
2,820
like
03/07/13 06:54 AM (11 years ago)
I'd take Rishav advice and create this dynamically on-the-fly, especially since there's a lot of fruit species, your list could become a maintenance issue using the control panel. Using loadScreenObject, you can dynamically create any screen you'd like, as long as you pass the correct attributes (ex: emailSubject) for it to work properly. Try to load this JSON in your data url (as a .txt file): { "childItems": [ { "itemId": "fruit1", "itemType": "BT_menuItem" "titleText": "Apple", "loadScreenObject": {"itemId":"email1", "itemType":"BT_sendEmail", "emailToAddress":"[email protected]", "emailSubject":"Question about your Fruit..."} } ... repeat this block for each Fruit Item, let BT create the sendEmail object dynamically ] }
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
03/07/13 07:13 AM (11 years ago)
I will have 200+ fruits, I don't want to make 200+ corresponding email screens. The creating of the 200+ fruit menu items is a one-time affair. I am okay with manually creating those menu items in the Control Panel. I also want to let the Client manage those fruit menu items in the Control Panel. I don't want to establish and maintain another "web app" to hold and manage and generate the JSON for the Fruit menu items and the email screens. I don't mind modifying the Menu and Email plugins to achieve my goals: - Pass the fruit item to the email screen - Use the Control Panel to manage all the content and screens What do I need to modify in the two plugins (iOS first)? Thanks! -- Niraj
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
03/07/13 07:17 AM (11 years ago)
@Rishav -- what is the "shared preference for Android"? Can you explain more? Even I am doing iOS for now, I might need Android later. For those who are curious, Found the answer in a long ago post: http://developer.android.com/guide/topics/data/data-storage.html#pref Thanks! -- Niraj
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/07/13 07:27 AM (11 years ago)
you can do this by modifying the menu with image plugin to create the email screens for you. Use the loadscreenobject method described above, but instead of doing it all in JSON, do it in code. When I'm near a computer again I can draft up a quick example if you need
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
03/07/13 07:37 AM (11 years ago)
@Chris -- yes please, grab a Computer and bang out an example please. :-) Since the email plugin class already exists, can we invoke it via your example code? That way, I won't have to duplicate all of its functionality. Thanks, -- Niraj
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/07/13 09:03 AM (11 years ago)
Try this out. Haven't tested it, but it should work. In your menu plugin code, find the method called: //on row select - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath Replace that entire method with the following: //on row select - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"didSelectRowAtIndexPath: Selected Row: %i", indexPath.row]]; //pass this menu item to the tapForMenuItem method BT_item *thisMenuItem = [self.menuItems objectAtIndex:indexPath.row]; if([thisMenuItem jsonVars] != nil){ //get title from menu row - this will become part of the email address (the part before the @ sign) NSString *getFirstPartOfEmailAddress = [BT_strings getJsonPropertyValue:thisMenuItem.jsonVars nameOfProperty:@"titleText" defaultValue:@""]; //generate email address from getFirstPartOfEmailAddress NSString *fullEmailAddress = [getFirstPartOfEmailAddress stringByAppendingString:@"@somewhere.com"]; //generate subject line for email NSString *emailSubjectLine = @"Question about your fruit..."; //create a unique itemId for the new screen NSString *currentID = [BT_strings getJsonPropertyValue:thisMenuItem.jsonVars nameOfProperty:@"itemId" defaultValue:@""]; NSString *newId = [currentID stringByAppendingString:getFirstPartOfEmailAddress]; //create json values for new screen NSMutableDictionary *tmpJsonValues = [[NSMutableDictionary alloc]init]; [tmpJsonValues setObject:newId forKey:@"itemId"]; [tmpJsonValues setObject:newId forKey:@"itemNickname"]; [tmpJsonValues setObject:@"BT_sendEmail" forKey:@"itemType"]; [tmpJsonValues setObject:fullEmailAddress forKey:@"emailToAddress"]; [tmpJsonValues setObject:emailSubjectLine forKey:@"emailSubject"]; //dynamically load a new instance of the Email plugin BT_item *screenObjectToLoad = [[BT_item alloc] init]; [screenObjectToLoad setItemId:newId]; [screenObjectToLoad setItemNickname:newId]; [screenObjectToLoad setItemType:@"BT_sendEmail"]; [screenObjectToLoad setJsonVars:tmpJsonValues]; //load next screen if it's not nil if(screenObjectToLoad != nil){ [BT_viewControllerManager handleTapToLoadScreen:[self screenData] theMenuItemData:thisMenuItem theScreenData:screenObjectToLoad]; }else{ //show message [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"%@",NSLocalizedString(@"menuTapError",@"The application doesn't know how to handle this click?")]]; } }else{ //show message [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"%@",NSLocalizedString(@"menuTapError",@"The application doesn't know how to handle this action?")]]; } }
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/07/13 09:06 AM (11 years ago)
Probably also want to "release" the NSDictionary and BT_item, just for proper memory management.
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
03/07/13 12:37 PM (11 years ago)
The timing on this is impeccable.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
03/07/13 11:30 PM (11 years ago)
@Chris is spot on with this. A few comments...and concepts...in case you're not aware of these... In most cases, the BT_viewControllerManager's handleTapToLoadScreen() is used to load the next screen. In this case, the "next screen" isn't a screen at all, it's a built in iOS compose sheet. I realize this may confuse some of you but it's an important distinction. Most plugins use their own UIViewController to display their content and features. Some do not. The email, call, sms "plugins" are a good examples of this. These methods doen't open an actual view controller but instead trigger a built in iOS method. This means that creating the "next screen" dynamically is about the only way to accomplish what @Niraj is asking about. BUT, in some cases, after loading the next screen, you may want to know what menu row / or button or whatever was "just tapped" and what screen the use "came from." This is easy... The app's delegate file has a property called rootApp. This rootApp object is an in memory representation of the app's JSON data. This rootApp object also has all sorts of other nifty properties too. Have a look at BT_Core/BT_application class for a list. In the case of trying to figure out what screen was just left or what row was just tapped, you could refer to the rootApp previousMenuItemData or previousScreenData property. Like.. BT_item *previouslyTappedRow = [appDelegate.rootApp previousMenuItemData]; OR... BT_item *previousScreen = [appDelegate.rootApp previousScreenData]; In most cases the BT_viewController class is used to load new screens by way of the handleTapToLoadScreen() method. This method takes a few arguments. Most importantly, what item was tapped and what item to load. These are remembered in the rootApp for exactly this reason, so you can refer to them anytime you need anywhere in any file throughout the project.
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
03/08/13 03:09 AM (11 years ago)
Thank you to @Alzooka, @Chris and @David, y'all have given us plenty to munch on! There are several ways to solve this problem: - With an external source such as a data file or data stream via loadScreenObject - Through code and variables Those little pieces of insight is how each of us make little quantum leaps! Thanks, fellas! :-) -- Niraj
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
03/08/13 07:00 PM (11 years ago)
This is beautiful.
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
03/09/13 01:58 PM (11 years ago)
What is the purpose of theMenuItemData in the BT_viewControlManager, and passing the *thisMenuItem into it? Can nil be passed to this?
 
nadthevlad
Code is Art
Profile
Posts: 1025
Reg: Jun 07, 2012
Denver
21,850
like
03/09/13 02:19 PM (11 years ago)
Chris, It seems like your doubling up on the itemID and itemNickname and itemType Your adding these to the tmpJsonValues, which gets added to screenObjectToLoad. But you then also add them to screenObjectToLoad. Am I wrong in thinking that this is duplicating these three json items.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/09/13 06:49 PM (11 years ago)
@nadthevlad: The method requires a BT_item to be passed for the arguments - I don't think nil will work, but you can try. The screenObjectToLoad takes a BT_item that has the item's id, nickname and type set in their own variables, as well as a JSON string (which also contains the the same). So yes, there is some doubling up of that, but it's how the process works. Not to worry - that small amount of code won't slow your app down any.
 

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.