Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 9    Views: 157

mutzy
Aspiring developer
Profile
Posts: 841
Reg: Nov 03, 2010
Medford, MA
9,860
11/05/12 02:07 PM (12 years ago)

How to connect Xib button to Buzztouch screen?

I am trying to make a custom plugin for my own app. I don't think it's applicable to others so not working on developing it for the BT plugin store at this point so no need to connect it to config.txt file (at least I don't think). My plugin is sort of a custom menu button screen as shown here: https://www.dropbox.com/s/607wths2jss26qs/test.png I have watched the webinar from 10/10 several times and have done everything up to the 50 minute mark. Now that I am into the .m file I am not sure how to declare the method for each method so that it loads a BT screen. Here's what it looks like so far: //buton 1 clicked... -(IBAction)toxclick:(id)sender{ } I tried looking at the BT button menu plugin but can't extract what I need. Any ideas?? Thanks! Josh
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
11/05/12 06:08 PM (12 years ago)
if([[BT_strings getStyleValueForScreen:thisMenuItem:@"loadScreenWithItemId":@""] isEqualToString:@"4F649FAFD0CA6BF6B711822"] || [[BT_strings getStyleValueForScreen:thisMenuItem:@"loadScreenWithItemId":@""] isEqualToString:@"FF73010054BA1975A9EDC68"]) { ACTION } else if { ACTION } } ITEM ID's can be found in CONFIG.TXT when you have created the screen. I believe this code should work correctly, might need to tweak it here and there. Cheers, David https://buzztouchmods.com
 
mutzy
Aspiring developer
Profile
Posts: 841
Reg: Nov 03, 2010
Medford, MA
9,860
like
11/05/12 09:37 PM (12 years ago)
Apparently it was at the very end of that first webcast... not sure how I missed it! But here's how Dave said to do it... and it works!!! Just wish I could get the icons to fade. hmmm //buton 1... -(IBAction)toxclick:(BT_item *)theMenuItem{ [BT_debugger showIt:self:@"toxbuttonclick"]; //appDelegate erres2_appDelegate *appDelegate = (erres2_appDelegate *)[[UIApplication sharedApplication] delegate]; //load new screen BT_item *mynextScreen = [appDelegate.rootApp getScreenDataByItemId:@"6A1EE4E3F0114DB0CDC27AA"]; //load next screen if it's not nil [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:nil:mynextScreen]; }
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
11/05/12 09:38 PM (12 years ago)
Easy. Thanks for the share ;) David. https://buzztouchmods.com
 
Susan Metoxen
buzztouch Evangelist
Profile
Posts: 1706
Reg: May 01, 2011
Hopkins, Minnes...
26,260
like
11/05/12 11:12 PM (12 years ago)
Way to go, Josh!! It is so cool what we can do with xib files.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
11/05/12 11:51 PM (12 years ago)
@mutzy: Did you get the icons to fade, wiggle, bounce, spin, whatever? It's a matter of running a quick animation on the button you tap....before you load the screen. These types of effects usually last about .3 seconds or so. Depends on the animation type I suppose? The method first (add tabs and spaces in Xcode, ugly code sucks)... //all buttons are connected to this IBOutlet... -(IBAction) buttonTapped: (UIButton*) sender{ UIButton *theButton = (UIButton *)sender; //fade out button... [theButton setAlpha:1.0]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.1]; [UIView setAnimationDelegate:self]; [theButton setAlpha:0.1]; [UIView commitAnimations]; //then back in... [theButton setAlpha:.1]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.2]; [UIView setAnimationDelegate:self]; [theButton setAlpha:1.0]; [UIView commitAnimations]; if(sender.tag == 1) { //load screen for button 1 } if (sender.tag == 2) { //load screen for button 2 } if (sender.tag == 3) { //load screen for button 3 } } Then the explanation...and some basics... --It's generally best to assign a unique tag (an integer) to each object on the screen. Each UI component. If using IB you can do this visually by expanding the View section of the object in the inspector panel. Objects are probably UIButtons in this case. Entering a number in the tag setting. Say 1, or 2, 3, 4, and so on. Each button (the object) gets it's own tag. Dont' use the same tag more than once. This allows you to easily identify which button is being interacted with. --It's usually best to connect all "like things" you use in interface builder to the same method. Say all the buttons, they should all be wired to the same method, just makes it easier. Same for UITextFields and other things...connect all "like things" to the same method. --The method I whipped up (above) uses... -(IBAction) buttonTapped: (UIButton*) sender "buttonTapped" is the name of the method (IBAction is Interface Builder Action) you connect all the buttons to. Drag the "touchUpInside" sent-event to this method in the Files Owner object. All buttons get the "buttonTapped" method assigned. "sender" is a reference (pointer) to the thing that was interacted with when the method fires. In this case, "sender" will be a button. "id" is a generic Objective C key word that means "any Objective C Object" In this case it could be UIButton because all the "senders" that fire this method will be button. Have a look at your method, the one a few posts up... you have.... -(IBAction)toxclick:(BT_item *)theMenuItem But...if you look at your method, the BT_item object (named theMenuItem is never actually used in your method. It's not hurting anything but suggest you're up for some learning :-) So..unless you know for sure you need a BT_item passed into the method, just use id instead - much easier. So, our method is getting triggered by a button...now we need to know what button was pressed. Here's where the tag come in... This line... UIButton *theButton = (UIButton *)sender; gets a reference to the "sender" and "casts" it to a UIButton. Remember, it's starting off as a generic type (id) that does not have a type. We need to tell iOS that sender is a button (it could be anything). Next, we animate the darned thing. Fade out then in. Simple but effective. You could alter all sorts of properties in this animation (position, size, etc) we are only altering the "alpha" value (0 is invisible). Next, after the animation completes, we load a different screen depending on which button was pressed. Whoo hooo. Summary: --Connect as many objects on the screen to as few IBActions as possible. --Give everything on the screen a "tag" with Inteface builder or in code with [myButton setTag:3]; --Use the generic "id" type for sending objects so you can be more flexible. --Cast the sender to the type of object you want to manipulate. --Learn with object was interacted with using the tag. --Do your magic. You're halfway there! LOL
 
mutzy
Aspiring developer
Profile
Posts: 841
Reg: Nov 03, 2010
Medford, MA
9,860
like
11/06/12 07:47 AM (12 years ago)
Wow. When I woke up and saw this morning I thought I was going to have to start from scratch but took me less than an hour! Buttons fade nicely now too. THANK YOU SO MUCH. I agree Susan, using Xib files just opened up so many doors!!! If I wanted to do fade transitions to the next screen as opposed to the usual slide transition would that be easy enough to do? Thanks again everyone! Josh
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
11/06/12 12:01 PM (12 years ago)
Webinar in :60 seconds so quick. See the "nil" in this statement [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:nil:mynextScreen]; "nil" is a placeholder for a BT_item. This BT_item is the "menu row" or "button" tapped. You can insert animationType="fade" in that objects JSON and it'll do what you want. More on this later, after the webinar :-)
 
mutzy
Aspiring developer
Profile
Posts: 841
Reg: Nov 03, 2010
Medford, MA
9,860
like
11/25/12 09:23 AM (12 years ago)
Dave, I've tried playing around with this but just can't get the transition to the next screen to fade. Here is an example from my config.txt file: {"itemId":"CFA500E73E8A3160ADDC0F8", "itemType":"BT_menuItem", "loadScreenWithItemId":"6A1EE4E3F0114DB0CDC27AA","titleText":"Toxicology", "transitionType":"fade"}, I have my button loading screen ID "6A1EE4E3F0114DB0CDC27AA" I even tried putting the transition login elsewhere in JSON data just for that menu screen: {"itemId":"6A1EE4E3F0114DB0CDC27AA", "itemType":"BT_screen_menuListSimple", "itemNickname":"Toxicology", "navBarTitleText":"Toxicology", "listBackgroundColor":"clear", "listRowBackgroundColor":"#ffffff", "listTitleFontColor":"#000000", "listDescriptionFontColor":"#000000", "listStyle":"plain", "preventAllScrolling":"0", "listRowSelectionStyle":"none", "listTitleFontSizeSmallDevice":"17", "listDescriptionFontSizeSmallDevice":"14", "listRowHeightLargeDevice":"100", "listTitleHeightLargeDevice":"100", "listTitleFontSizeLargeDevice":"30", "listDescriptionFontSizeLargeDevice":"25", "hideFromSearch":"1", "transitionType":"fade", "childItems" etc etc etc It still won't fade. Any ideas? Josh
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
11/25/12 10:08 AM (12 years ago)
Hi Josh... Battling through an all nighter with server issues. You probably saw the message in your control pane? Sigh....we'll get though it, just lame! Transition Types: Yup, makes perfect sense. The method you're using to load the next screen is probably the built in handleTapToLoadScreen in the BT_viewControllerManager class. Cool. This method takes three arguments (three things, three objects) as the parameters. If you call it like this (where mynextScreen is the new screen to load)... [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:nil:mynextScreen]; In English, you're saying: "Hey BT_viewControllerManager thing, load this next screen with these three arguments: The current screen's data (self.screenData), nil, and mynextScreen" So far so good. Then, you added "transitionType":"fade" in a few different places in some screenData JSON. This is where you're confused a bit. SCREENS do not understand what tranitionType's are. Menu items and buttons and things you tap do. Think of it this way...if you had a map with a "transition type" setting, that map would transition in / out the same way every time it loaded. This may not be good. What would happen if on one screen you wanted to "fade" in the map, but on another screen you wanted to "slide up" the map? Lame. You would have to make to different maps to do this if the transitionType were associated with the map itself. Lame again. The solution is to associate the transitionType with the menu item, button, image, whatever is tapped to load the next screen. This is the "nil" argument you see in the method call above. So, to do this dynamically, you'll need to create two things to "pass" into the handleTapToLoadScreen method. A "menu item" object (the thing that was clicked) and the "next screen." The menu item object's JSON data would contain the transitionType. The good news is this...both of these things are BT_items so it's super easy to create as many of them as you want or need. Like... Create a menu item object. The only reason we are creating this is so we can pass a transitionType. //create the JSON for the next menu item... NSString *tmpJSON =@"{\"itemId\": \"na\",\"itemType\": \"BT_buttonItem\", \"transitionType\":\"fade\"}"]; NSDictionary *tmpDictionary = [tmpJSON JSONValue]; //create the BT_item representing the button, use the JSON above... BT_item *tmpButton = [[BT_item alloc] init]; tmpButton.itemId = @"na"; tmpButton.itemType = @"BT_buttonItem"; tmpButton.jsonVars = tmpDictionary; //now we have a button, and the screen you already figure out how to make....pass both of these things to the handleTapToLoadScreen method: [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:tmpButton:mynextScreen]; //Magic! //release the memory we allocated for the tmpButton (you may want to do this for the mynextScreen object you created too, it depends on how you did it... [tmpButton alloc]; This approach allows you to create things dynamically, without relying on what's in your config.txt data. Smile. Out.
 

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.