Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 10    Views: 133

Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
12/28/13 12:22 PM (11 years ago)

Some Add to Favorites code

We know we can add a add to favorites button on each type of plugin we want with a couple of lines of code. Some have asked if we can set in the control panel. We can by adding and amending a few lines of code in the BT_viewController.m file first add #import "AK_favorites.h" with the other headers at the top of the file. The around line 311 find if([navBarRightButtonType isEqualToString:@"add"]) theBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:selector ]; replace it with this if([navBarRightButtonType isEqualToString:@"add"]) theBarButtonItem = [[AK_favorites favoritesManager]favoritesAddButton]; now every time in the control panel when you set the add button in the navbar details that will make a favourites add button. Obviously you wouldn't be using an add button elsewhere because you wouldn't want to confuse your users would you?
 
Joe Sprott
Code is Art
Profile
Posts: 414
Reg: Aug 20, 2011
Melbourne, FL
10,290
like
12/28/13 12:41 PM (11 years ago)
thanks man
 
AppGuy30
Code is Art
Profile
Posts: 737
Reg: Oct 29, 2011
location unknow...
14,070
like
12/28/13 03:36 PM (11 years ago)
When i added the code to the BT_viewController.m file i got the error below (see picture). https://www.buzztouch.com/applications061013/JA70107B558DE18931156AC57/images/Screen%20Shot%202013-12-28%20at%205.42.50%20PM.png
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
12/28/13 03:50 PM (11 years ago)
Have you added the #import at the top of it
 
AppGuy30
Code is Art
Profile
Posts: 737
Reg: Oct 29, 2011
location unknow...
14,070
like
12/28/13 04:02 PM (11 years ago)
Ahh rookie mistake aha, thank you very much @Kittsy for your excellent support.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
12/28/13 04:04 PM (11 years ago)
The clue was "the first" lol Look forward to seeing what you make with it
 
Jake Chasan
Veteran developer
Profile
Posts: 1685
Reg: May 13, 2011
location unknow...
29,650
like
12/28/13 08:15 PM (11 years ago)
Do does this make the app only display one right nav bad button? Jake
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
12/29/13 03:27 AM (11 years ago)
Yup on the screens you want to add to a favourites list. It's just another way of adding the button, the plugin gives you the code to make anything the favourite button.
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
12/31/13 08:32 AM (11 years ago)
I've been tinkering with an "Add to Favorites" custom button for an XIB layout. Instead of using the green/red tint color to determine if a screen is in the favorites - I want a button onthe screen that has a label which will tell you if the screen is in your favorites. Like: "This screen IS in your favorites list" or "This screen is NOT in your favorites list" and that button.titleLabel will display on the UIButton after it runs the checkIfFavorite method. I'm curious how you might approach a mod like this with this awesome plugin? I've got the button working and it's adding/removing from the favorites list - but struggling with getting the button text to update properly. Would you suggest setting the button.titleLabel inside that checkIfFavorite method?
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
12/31/13 08:51 AM (11 years ago)
You would put something similar to this this in the view will appear method if([[AK_favorites favoritesManager]checkIfFavorite]){ [button setTitle:@"This is a fav" forState:UIControlStateNormal]; }else{ [button setTitle:@"This is a fav" forState:UIControlStateNormal]; } Then in the button selector method also if([[AK_favorites favoritesManager]checkIfFavorite]){ [button setTitle:@"This is a fav" forState:UIControlStateNormal]; }else{ [button setTitle:@"This is a fav" forState:UIControlStateNormal]; } so the button title changes when pressed
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
12/31/13 09:57 AM (11 years ago)
Thank you. I will tinker around with this after I sober up from the NYE vacation, that makes perfect sense. Hope you are parked in some pub getting lacquered with your new partner!
 

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.