Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 8    Views: 85

PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
03/17/14 06:55 PM (10 years ago)

Linking custom buttons to other screens?

Hi folks, I'm playing with the nav bar on my map screen and have set up 'custom' left and right nav buttons so they can perform 'non-standard' actions (ie actions outside the CP settings). One is a built-in iOS "+" sign, the other is an icon I made for the project. They are inserted into BT_viewController.m like this: if([self.screenData.itemType isEqualToString:@"BT_screen_map" ]){ UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemAdd) target:self action:@selector (addNewPlace)]; [self.navigationItem setLeftBarButtonItem:leftButton]; and UIBarButtonItem *listItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"list.png"] style:(UIBarButtonItemStylePlain) target:self action:@selector (openListView)]; NSArray *actionButtonItems = @[listItem]; self.navigationItem.rightBarButtonItems = actionButtonItems; This looks peachy, but I'm struggling to find out how to now 'call' the two methods there, addNewPlace and openListView (which don't exist yet, they are just my placeholders to remind me what I want the buttons to do). The only thing those 'methods' need to do is open other screens that are already part of the project. I've looked at the 'how to make a button do anything tutorial', <a href="http://www.buzztouch.com/files/howtos/make-a-button-do-anything.pdf" target="_blank" rel="nofollow">http://www.buzztouch.com/files/howtos/make-a-button-do-anything.pdf</a>, but it has shown me that I don't understand the relationships between the files and what an app delegate does. So I'm scrounging for insights! Given that the screens I want these buttons to link to already exist (rather than needing to write 'new' methods), I'm hoping that there is a kind of BT-equivalent of a hyperlink that I can just add to these buttons... maybe just replacing my 'openListView' method name with the name of the screen I want the button to open? (But I know it couldn't be that easy and of course it broke when I tried that...) If anyone could point me to a place where I can get my head around how to do this I'd be most grateful. Cheers Paddy
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/17/14 07:33 PM (10 years ago)
-(void)addNewPlace { [BT_debugger showIt:self message:@"addNewPlace"]; BT_appDelegate *appDelegate = (BT_appDelegate *)[[UIApplication sharedApplication] delegate]; BT_item *screenToLoad = [appDelegate.rootApp getScreenDataByItemId:@"someItemIdHere"]; [self loadScreenObject:screenToLoad]; }
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/17/14 07:36 PM (10 years ago)
What he said. ;) Cheers! -- Smug
 
PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
like
03/17/14 07:41 PM (10 years ago)
Thank you thank you thank you!! Wow, that looks way easier than I'd imagined. Where do I put that - after each button definition or does it go in some other special file that's filled with methods?
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/17/14 08:45 PM (10 years ago)
It's a method to go in your .m file. Your button code above is probably in the viewWillAppear method. You can put this method after the viewWillAppear method is finished (after the closing } bracket).
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/17/14 08:46 PM (10 years ago)
Tip: use code folding to see all the methods in your plugin file quickly and to easily find a place for a new method.
 
PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
like
03/17/14 09:24 PM (10 years ago)
Thanks Chris. It works beautifully, I'm really thrilled and I'm grateful (again!) for the generosity here. Hadn't discovered code folding before, that will be a huge help. Cheers Paddy.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/18/14 06:47 AM (10 years ago)
No problem - glad to help out!
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
03/19/14 06:17 AM (10 years ago)
-(void)addNewPlace { [BT_debugger showIt:self message:@"addNewPlace"]; BT_appDelegate *appDelegate = (BT_appDelegate *)[[UIApplication sharedApplication] delegate]; BT_item *screenToLoad = [appDelegate.rootApp getScreenDataByItemId:@"someItemIdHere"]; [self loadScreenObject:screenToLoad]; } See if you can replace "getScreenDataByItemId" with "getScreenDataByItemNickname" or something similar. That will make your code be Control Panel friendly. To get close to the solution, right click on "getScreenDataByItemId" and select Jump to Definition. That takes you to the class file for that code. Look in that file for the word "nickname". Hunt-and-peck ... -- Niraj
 

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.