Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 8    Views: 62

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

Identifying a specific screen from within BT_viewController?

Hi all, First time playing inside Xcode. Taking a deep breath... I want to customise the nav bar on one screen. I'm inside BT_viewController where it sets up the nav bar, as in: //setup navBar... [self configureNavBar]; Based on a suggestion from @chris1 on another thread here: https://www.buzztouch.com/forum/thread.php?tid=5A8543A671BCAE7EE3CB5D7&fid=BC70C36A743CD4FAD95D17F&sortColumn=FT.id&sortUpDown=DESC&currentPage=2 - I'm modifying the nav bar with a button, like this: if([self.screenData isScreenName]){ UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWith:@"text" style:UIBarButtonSystemItemAdd target:self action:@selector(suggestNewPlace)]; [self.navigationItem setLeftBarButtonItem:leftButton]; } My question is, where I have "isScreenName" as a placeholder, how do I know what my target screen is actually called inside Xcode? Cheers Paddy.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/11/14 10:30 PM (10 years ago)
you would probably want to parse to see if a certain json value exists, such as screenNickname or something distinct and unique… If this is the case, you could probably do something 'similar' to: if([[self.screenData.jsonVars objectForKey:@"screenNickname"] isEqual: @"myCoolScreen"]) { // something goes on in here, I'm sure of it. } "screenNickname" would be the actual json 'key' you wanted to look at, and 'myCoolScreen' would be the value that you seek. worth a shot, anyway… Cheers! -- Smug PS, my concepts are sound. My syntax isn't always. buyer beware.
 
PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
like
03/12/14 12:07 AM (10 years ago)
Thanks Smug, you're spot on - your concepts are very sound!! This particular one led me to discover that (I think) it might be even easier than your syntax suggests. See if this makes sense. This first snippet allows for the change (whatever it is; in my case some nav bar button changes) to be made to just the one screen with its unique BT itemId: if([self.screenData.itemId isEqualToString:@"2FCE8AD101DBEDB5D5C33F8" ]){ //then cool stuff happens on that screen } So does this, for when you just can't be bothered remembering all those itemId numbers (assuming that this is the same screen with an itemId of 2FCE8AD101DBEDB5D5C33F8 and a Nickname of babysFirstScreen: if([self.screenData.itemNickname isEqualToString:@"BabysFirstScreen" ]){ //then the same cool stuff happens on that same screen } But THIS, on the other hand, allows for ALL screens in the app that are based on the same plugin to receive the benefit of whatever is being changed, but just using one snippet to do it: if([self.screenData.itemType isEqualToString:@"BT_screen_map" ]){ //then the same cool stuff will happen on all screens that are built on the BT_screen_map plugin } The cool thing about this is that depending on which one you use it could give more or less 'pervasiveness' through multiple screens. What do you think? Cheers Paddy
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/12/14 12:23 AM (10 years ago)
I wasn't sure if you wanted one particular screen or all of them but you're right; you can check for itemType, screenNickname, itemId (but egads, why? lol!) and handle them all the same, or differently, depending on your whims. And of course, since you're doing 'location based' services you could get really funky and add options depending on the entry 'category', or if you want to get really dirty, you could have one option if the coordinates were in this area, and you could have another option if the coordinates were in that area. If it's in the JSON, you can use it to filter whatever. A bit of detail work, but the possibilities are literally endless. Cheers! -- Smug
 
PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
like
03/12/14 12:54 AM (10 years ago)
Beautiful. This is what I ended up adding inside BT_viewController.m to add a new left and right button on the nav bar for my map screen. Hopefully someone else might get some use out of it - I'd been poking around for quite a while to get here. It gives the iOS system "+" sign as the left button (UIBarButtonSystemItemAdd), and the BT "location" icon as the right one. Just below this, which is already in the BT_viewController.m file: //setup navBar... [self configureNavBar]; Add this: if([self.screenData.itemType isEqualToString:@"BT_screen_map" ]){ UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemAdd) target:self action:@selector (addNewPlace)]; [self.navigationItem setLeftBarButtonItem:leftButton]; UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"bt_location.png"] style:(UIBarButtonItemStylePlain) target:self action:@selector (nearMe)]; [self.navigationItem setRightBarButtonItem:rightButton]; } Cheers Paddy.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
03/12/14 01:09 AM (10 years ago)
Does the left button 'augment' the existing 'back' button, or does it replace it? Cheers! -- Smug
 
PaddyO
Lost but trying
Profile
Posts: 189
Reg: Sep 11, 2013
Geelong
5,190
like
03/12/14 01:14 AM (10 years ago)
It replaces it. Didn't need to remove the default 'Back' button, this just overrides it. Cool huh? Cheers Paddy.
 
Susan Metoxen
buzztouch Evangelist
Profile
Posts: 1706
Reg: May 01, 2011
Hopkins, Minnes...
26,260
like
03/12/14 10:28 PM (10 years ago)
Great post, PaddyO and Smug! This will help a lot of people.
 
RonBo
buzztouch Evangelist
Profile
Posts: 167
Reg: Feb 26, 2012
Raleigh, NC
5,220
like
05/06/14 06:24 AM (10 years ago)
Great stuff for sure, thanks. Trying to figure out this for a tabbed app. Each of may tab screens is running a Menu List Simple, so I'm able to add this code into my BT_screen_menuListSimple.m. //put in viewDidLoad // CGPoint origin = CGPointMake(0.0,0.0); // bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait origin:origin]; // bannerView_.adUnitID = @"ca-app-ID_xxxxxx"; // bannerView_.rootViewController = self; // [self.view addSubview:bannerView_]; // [bannerView_ loadRequest:[GADRequest request]]; } This is working fine, but I am not able to target specific house ads for each tab screen (by specifying a different adMob adUnitID for each tab screen). My question is: in my tabbed app, where could I use PaddyO's logic to identify specific tab screens? Would I have to run this in BT_tabBarController.m? I am going to try this: (when I get back to my mac..) In BT_tabBarController.m, right before this existing code.. //if this view controller has a property named "rotating" set it to false... add something like this to identify each of my tab screens: if([self.screenData.itemNickname isEqualToString:@"tabScreenBlah" ]){ //hoping to call specific adMob House Ads for each tab screen // CGPoint origin = CGPointMake(0.0,0.0); // bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait origin:origin]; // bannerView_.adUnitID = @"ca-app-ID_forTabScreen1"; // bannerView_.rootViewController = self; // [self.view addSubview:bannerView_]; // [bannerView_ loadRequest:[GADRequest request]]; }
 

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.