Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 4    Views: 80

HerrNathan
Aspiring developer
Profile
Posts: 73
Reg: Oct 11, 2011
Stirling
5,830
03/08/13 12:32 PM (12 years ago)

Menu with Image - Customizing Plug In - Have I done it right???

Hi, I'm using the menu with image plugin to display a top 10 list which changes on a daily/weekly basis. On clicking the menu item it should take you to a custom URL of that page. So it needs to pass a specific url Ideally I'd only want to create a single custom url page and pass thru the details of the list item. Obviously there is no pre-set way to do this so to achieve this I've had my first go at modifying some of the iOS code. What I've done is to set up a php code to create the menu list {"childItems":[ {"itemId":"101", "itemType":"BT_menuItem", "loadBFUrl":"http://DOMAINNAME.COM/?id=1", "titleText":"Item1", "descriptionText":"txt", "iconName":"icon.png"}, {"itemId":"102", "itemType":"BT_menuItem", "loadBFUrl":"http://DOMAINNAME.COM/?id=2", "titleText":"Item2", "descriptionText":"txt", "iconName":"icon.png"}, {"itemId":"103", "itemType":"BT_menuItem", "loadBFUrl":"http://DOMAINNAME.COM/?id=3", "titleText":"Item3", "descriptionText":"txt", "iconName":"icon.png"} ]} this seems to work fine. In the plug in I've added the following section // find URL from JSON NSString *loadScreenURL = [BT_strings getJsonPropertyValue:thisMenuItem.jsonVars nameOfProperty:@"loadBFUrl" defaultValue:@""]; // Custom URL Passed from JSON if([loadScreenURL length] > 1){ NSString *tmpJSON = [NSString stringWithFormat:@"{"itemId": "na","itemType": "BT_screen_customURL", "dataURL":"%@"}", loadScreenURL]; NSDictionary *tmpDictionary = [tmpJSON JSONValue]; screenObjectToLoad = [[BT_item alloc] init]; [screenObjectToLoad setItemId:@"NA"]; [screenObjectToLoad setItemNickname:@"NA"]; [screenObjectToLoad setItemType:@"BT_screen_customURL"]; [screenObjectToLoad setJsonVars:tmpDictionary]; NSLog(@"custom url called"); } This seems to work on simulator, However, I'd still class myself as a total novice in Objective C. screenObjectToLoad is already within the code, I've added loadScreenURL and NSString *tmpJSON but Im really not sure about what else I need to do. Is there a "cleaner" way to achieve this?
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/08/13 01:34 PM (12 years ago)
Have you read this thread:? https://www.buzztouch.com/forum/thread.php?tid=64A97C87E9AD0EABAAE26EA&currentPage=3 I think it has the answers you seek...
 
HerrNathan
Aspiring developer
Profile
Posts: 73
Reg: Oct 11, 2011
Stirling
5,830
like
03/08/13 02:32 PM (12 years ago)
@Chris thanks for the reply - yeah I had seen that thread (and another earlier one where there was a solution for a similar Map co-ordinate problem). Actually, my solution was just a re-work of the code within these pages (as you may have noticed :D ) I noticed Davids reply mentioned previousScreenData property and was wondering if that was the best way to implement it. As I said, it seems to be working as expected but, being a novice to this, I'm very cautious to make sure I dont learn any bad coding habits. In one of your replies you mentioned quote: Probably also want to "release" the NSDictionary and BT_item, just for proper memory management. Should I have added [tmpDictionary release]; in the code?
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
03/08/13 02:46 PM (12 years ago)
You should only need to release objects you've done an alloc-init on. So in your example, you don't need to release the tmpDictionary, but you probably should release the screenObjectToLoad. You're using a slightly different method than what I suggested to create the json dictionary. Mine is a little easier to read, but takes a few more lines of code. If yours is working and you're happy with it, then you should be fine. There's always multiple ways to accomplish something in code, and people tend to disagree on what is "best practice". It probably is a good idea to implement David's suggestion here, since you're not just loading a function like email, but actually loading a new screen. Keeping that history will help with things like the user hitting the 'back' button on the navigation bar.
 
HerrNathan
Aspiring developer
Profile
Posts: 73
Reg: Oct 11, 2011
Stirling
5,830
like
03/08/13 02:57 PM (12 years ago)
Cheers! That gives me something to work away at :) Thanks again Chris.
 

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.