Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 13    Views: 109

Moto110
Aspiring developer
Profile
Posts: 205
Reg: Jul 26, 2011
Orlando, FL
8,700
03/10/15 07:43 PM (9 years ago)

How can I add a button to a .xib file to open BT Custom HTML screen?

I am modifing the .Storyboard (.xib) file in the Collector plugin. How can I add a button to the .xib file that will open a BT Custom HTML screen I have created in my app? I'm assuming I need to create an IBAction with the code (method) to actually do this. I know how to create the IBAction in the .h and .m file of the viewcontroller and then connect that IBAction method to the button I created in the .xib file. I need help writing the actual code that will call the BT CustomHTML screen with the correct screen ID. Any suggestions? Thanks.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
03/11/15 02:43 AM (9 years ago)
I go to stackoverflow as I often find somebody has asked the question before me. Be aware that I cannot code, so I hope my link is not miles out. http://stackoverflow.com/questions/21602260/cant-create-ibaction-connections-in-xcode-5-storyboard Cheers, Alan
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/11/15 05:36 AM (9 years ago)
Well, what needs to be done is: Create a new method to react to the button: - (IBAction)buttonClick:(id)sender { // your code will go in here... } And you'll need to tailor your code for the screen you want to launch. Take a look at this post, and read closely what Chris1 has to say about assembling a 'BT_item' and launching a screen from it. https://www.buzztouch.com/forum/thread.php?tid=64A97C87E9AD0EABAAE26EA&fid=BC70C36A743CD4FAD95D17F&sortColumn=FT.id&sortUpDown=&currentPage=66 Stop back with more questions if it gets confusing. Cheers! -- Smug
 
Moto110
Aspiring developer
Profile
Posts: 205
Reg: Jul 26, 2011
Orlando, FL
8,700
like
03/11/15 01:06 PM (9 years ago)
In my AN_CollectorViewController.M file I have this. I also added the appropriate code to the .h file and connected this to the button in the .xib file. -(void)imgSearch:(id)sender;{ //dynamically load a new instance of the BT_screen_customURL plugin BT_item *screenObjectToLoad = [[BT_item alloc] init]; [screenObjectToLoad setItemId:@"MY SCREEN ID HERE"]; [screenObjectToLoad setItemNickname:@"MY SCREEN NICKNAME HERE"]; [screenObjectToLoad setItemType:@"BT_screen_customURL"]; } This does not crash when I touch the button. However, it does not load the BT_screen_customURL nor does it do anything. I am obviously missing something. The example you provided from Chris1 assumes you are creating the screen on the fly using the JSON bt_config.txt file. The link was helpful, but because my screen already exists it seems the code I need would be a lot different. I added the customURL screen I want to a BT_screen_menuListSimple screen and it works great. If I could just figure out what code the BT_screen_menuListSimple is using to call the screen BT_screen_customURL I think I would be good to go. I just can't figure out how to port that functionality to a .xib file for use with a button. Any suggestions. It seems like this should be easy since nothing has to be grab from the BT_Config to build the link to the customURL screen and the values of the screen I want to load can be hard coded into the method to load the screen.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/11/15 03:55 PM (9 years ago)
You've 'built' the BT_item but you're not doing anything with it. Try adding this code as well (and modifying it slightly for your needs) //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?")]]; } Cheers! -- Smug
 
Moto110
Aspiring developer
Profile
Posts: 205
Reg: Jul 26, 2011
Orlando, FL
8,700
like
03/11/15 07:43 PM (9 years ago)
I have come to the conclusion that I need to spend my time working on other aspects of my add and don't really need the button on the .xib layout since I can still access it from a BT Menu screen. I did find this post on the BT forum. <a href="http://www.buzztouch.com/forum/thread.php?tid=83B6E67EC49DC92F51FBF95&currentPage=221" target="_blank" rel="nofollow">http://www.buzztouch.com/forum/thread.php?tid=83B6E67EC49DC92F51FBF95&currentPage=221</a> This link seemed to be exactly what I was looking to accomplish, but I was never able to test it since I couldn't get the the error "No Known Class Method for Selector: handleTapToLoadScreen" fix and was not able to build the app. I tried a bunch of different thing to fix the error and couldn't figure it out. I added #import "BT_viewController.h" to my .m file thinking that if I imported the BT_viewController it would find the handleTapToLoadScreen method in it. This did not help. Below is the final code I was trying that returned the error about the handleTapToLoadScreen. -(IBAction)imgSearch:(id)sender;{ //appDelegate MYAPPNAME_appDelegate *appDelegate = (MYAPPNAME_appDelegate *)[[UIApplication sharedApplication] delegate]; //load new screen BT_item *mynextScreen = [appDelegate.rootApp getScreenDataByItemId:@"MY SCREEN ID"]; //load next screen if it's not nil [BT_viewController handleTapToLoadScreen:[self screenData]:nil:mynextScreen]; } The code I found in the link I posted above referenced the BT_viewControllerManager instead of BT_viewController, but that produced an error. When I renamed it to BT_viewController the error went away. I assume something changed between BT versions and this was renamed. If anyone has any suggestions on how to fix this I am willing to try it. Thanks!
 
mutzy
Aspiring developer
Profile
Posts: 841
Reg: Nov 03, 2010
Medford, MA
9,860
like
03/12/15 06:19 AM (9 years ago)
Do you have the xib button menu plugin? You can just copy and paste the code.
 
mutzy
Aspiring developer
Profile
Posts: 841
Reg: Nov 03, 2010
Medford, MA
9,860
like
03/12/15 06:25 AM (9 years ago)
Duplicate post
 
Moto110
Aspiring developer
Profile
Posts: 205
Reg: Jul 26, 2011
Orlando, FL
8,700
like
03/12/15 06:28 AM (9 years ago)
I do not have that plugin. Can you provide me the code to link a button to a BT screen from that plugin? If you want send it over a direct message if posting it would be frowned upon since it is a paid plug and you don't want to share the secret sauce. I'm sure there is a lot more to that plugin than just linking a button to a BT screen. :~)
 
mutzy
Aspiring developer
Profile
Posts: 841
Reg: Nov 03, 2010
Medford, MA
9,860
like
03/12/15 06:50 AM (9 years ago)
1. It's not my plugin so I probably shouldn't. But for starters if you are talking about connecting a button then maybe try this instead: -(IBAction) imgSearch: (UIButton*) sender{ 2. And make sure you have this at the top of your .m file @synthesize imgSearch; 3. And make sure you connect the UIButton in the xib file to the imgSearch method
 
mutzy
Aspiring developer
Profile
Posts: 841
Reg: Nov 03, 2010
Medford, MA
9,860
like
03/12/15 06:55 AM (9 years ago)
You could always send it to me via email if you want and I'll have a quick look, no guarantees.
 
Moto110
Aspiring developer
Profile
Posts: 205
Reg: Jul 26, 2011
Orlando, FL
8,700
like
03/12/15 07:28 PM (9 years ago)
@mutzy - I watched the Buzzcast you recommend and it had a LOT of great information in it. David actually covered adding a button to a .xib and launching another screen at 1 hour 17 minutes and 30 seconds if anyone is interested in watching it. However, I think the code used in the video is outdated due to BT core updates and that is why my code is not working. Here is a link to the video. https://www.youtube.com/watch?v=OJrMVTn8z0s I used the exact code in the video but I can't get past the error I received from the handleTapToLoadScreen in the code shown below. It says: Method definition for "handleTapToLoadScreen:theMenuItem" not found at the @implementation AN_CollectorViewController in the .m file and No know class method for selector handleTapToLoadScreen:::: on the actual line of code shown below. //load next screen if it's not nil [BT_viewController handleTapToLoadScreen:[self screenData]:nil:mynextScreen];
 
mutzy
Aspiring developer
Profile
Posts: 841
Reg: Nov 03, 2010
Medford, MA
9,860
like
03/13/15 12:48 AM (9 years ago)
Did you add @synthesize imgSearch; to the top of your .m file? And did you try replacing: [BT_viewController handleTapToLoadScreen:[self screenData]:nil:mynextScreen]; with: [self handleTapToLoadScreen:[self screenData]:nil:mynextScreen];
 
Moto110
Aspiring developer
Profile
Posts: 205
Reg: Jul 26, 2011
Orlando, FL
8,700
like
03/13/15 06:51 AM (9 years ago)
I have @synthesize imgSearch; in my .m file and I have tried the code you suggested as well as many different options and it still does not like something about the handleTapToLoadScreen statement.
 

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.