Wednesday, July 27, 2011

New/Better way of releasing object?

Noticed some codes are using a new (better?) way of releasing objects in the "dealloc". As below, an extra "," was added and then followed by assigning it to "nil"... Which is quite interesting...- (void)dealloc{    [_window release], _window=nil;    [_viewController release], _viewController=nil;    [super dealloc...

Less typing required!

Not sure when did this start, but now when I create a new project in XCode 4, found that in the header ".h" file, the default property/variable disappeared!As below, at the line where I put the "//", we used to have to repeat the declaration of "UIWindow *window" and "ScrollViewTestViewController *viewController;", now it all disappeared - which is cool as we can now save some typing...#import <UIKit/UIKit.h>@class ScrollViewTestViewController;@interface ScrollViewTestAppDelegate : NSObject <UIApplicationDelegate> {//}@property (nonatomic, retain)  UIWindow *window;@property (nonatomic,...

What is "ViewPort" ?

As I mentioned in this previous post, in the HTML code example I used this META tag "<meta name='viewport' content='initial-scale=1.0' />".I learned that from Chapter 24 "Web Views" of book "Programming iOS4". The author says according to "Safari Web Content Guide" "if no viewport is specified, the viewport can change when the app rotates. Setting the initial-scale causes the viewport size to adopt correct values in both orientations."I searched the net and found This article from Safari Web...

UIWebView with MathJax working!

After a few tests, I was able to get a few weird Math formulas display working in a UIWebView using MathJax as shown in screen dump below.The codes are based on examples from This page on MathJax site, I stripped out the CSS/JS files and converted into a long NSString as below. Then based on parameter passed on from the caller, concatenated into a long string, write it into a temp HTML file.    NSString *foo = @"<html><head><meta name='viewport' content='initial-scale=1.0'...

Friday, July 22, 2011

Any one knows how to create fractions, square roots and other math formulas?

Was looking for ways to create fractions, square roots and other math formulas by code in Objective-C but not very successful...For example this 'Wolfram Math World' site has lots of stuffs (like the one using .GIF file shown below) but all done using .GIF files, wonder how they create those files?[UPDATE 1] Saw some discussions about "MathJax", "jsMath" and a few other stuffs on the net, but most of them are about JavaScript libraries, not for Objective-C and none of them seem easy to...

Tuesday, July 19, 2011

Some fonts not printed correctly on "Cocoa with Love" site

Found this site called Cocoa with Love with lots of handy information, lots of them still too difficult for me unfortunately :-( ...Was looking at this page called  Easy custom UITableView drawing, printed out from work to read it on the train. But as below (scanned from the print out), some of the words somehow not recognisable at all??!!However when viewed from browser there's no problem at all.... very strange...Checked the source, those fonts are covered in "<code></code>"...

Monday, July 18, 2011

Glass Button Generator

Was looking for ways to draw those nice glass buttons on the net, found this link from Anders Brownworth which not only generates a beautiful glass button, it also saved it as a .PNG file which you can then re-use in the future, which is pretty cool!Played around with it a bit, and added some looping and tried to covered lots of colours (colorWithHue accepts value from 0 to 1 only)  and when executed will almost fill up the screen with glass buttons in different colours as shown...

Sunday, July 17, 2011

How to assign initial values to variables in your init methods with proper memory management

A simple but important technique learned from Chapter 15 of the book "Learn Objective-C on the Mac", which I think is quite important when you are assigning initial values to variables in your init methods.@implementation Thingie @synthesize name; @synthesize magicNumber; @synthesize shoeSize; @synthesize subThingies;- (id)initWithName: (NSString *) n        magicNumber: (int) mn          shoeSize: (float) ss {        if (self = [super init]) {        self.name = n;    ...

Saturday, July 16, 2011

Colour Picker Test

Still don't know much about UIAlertView and other system default dialog boxes. Was testing this Colour Picker code from http://www.skylarcantu.com/blog/2009/08/14/custom-uialertview-color-chooser/As screen dump above, quite nice but still don't fully understand some of the codes yet unfortunately...For example, inside "presetSlidersWithColor" and "presetSlidersWithRandomColor", how come only calls[self performSelector:@selector(redSliderValueChanged:) withObject:redSlider afterDelay:0.0];Then,...

Sometimes, don't listen to the compiler

Was testing this "colour picker" code from http://www.skylarcantu.com/blog/2009/08/14/custom-uialertview-color-chooser/. As below, compiler gave me warning about "Using the result of an assignment as a condition without parenthesis". The suggestion is "use '==' to turn this assignment into an equality comparison" and "Place parentheses around the assignment to silence this warning".I followed that and then noticed....wait...that's not right!The author was actually combining the following 2...

Wednesday, July 13, 2011

Strange XCode error when switching between XCode 3 and 4 - fixed

I have a machine at home running XCode 4 and a VMware virtual machine on my laptop running XCode 3. When I have to load the projects on different version on XCode, it gives me some strange error.Opening XCode 4 saved projects on XCode 3 is easy, just change the "Project Properties" and choose the correct SDK.But when I tried to open XCode 3 saved projects on XCode 4, as below it gives me tones of error "LLVM GCC 4.2 Error" "Operator '<' has no left operand", and the file that got those error...

Do we really need "UIViewController"?

I studied the "Scratch Off Effect" code from http://buildingmyworld.wordpress.com/ and found a very interesting thing.There's only a "main.h", an "AppDelegate", 2 "UIView" and - - - an "UIViewController" which is not been used at all. If you look at the blog, the author also mentioned "btw: there is a view controller called ScratchTiceketViewController. Just ignore it. It was my test view controller and I’m to lazy to remove it )"So I inserted a few NSLog in each of the methods to show how/when...

Better "TestingScratchTicketEffekt" project than mine

Had a quick look at that http://buildingmyworld.wordpress.com/ link I mentioned in previous post.As below, it works like magic! First it shows this full screen covered in orange colour. If you move your finger/mouse pointer around, it will "scratch" off the orange colour and reveal the nice Apple image below. The source code is also available on that blog. Thanks for the sharing and it's definitely much better than mine. The best part is - everyone knows how to do it now, ha ...

Image Mask Test Project

As mentioned in this post on iPhone Dev SDK forum, there's this discussion about how to create a dynamic mask. Where a mask layer is presented above another photo layer and when user moves his/her finger on it, the photo below will be revealed.This sounds like an interesting project, although have to admit it's far beyond my level of objective-c skills..... Did some research and found 2 links:http://www.iphonedevsdk.com/forum/245649-post15.htmlhttp://www.ifans.com/forums/showthread.php?t=132024which...

TicTacToe V2.1 leaking fixed

Ok, spent some time today playing around "instruments" and browsing the net learning how to fix memory leak. I think it should be fixed now, as when I re-run "instruments" the result is as shown below, there's no more leaking! Yeah!Most of the issues are related to NSString handling. If you compare the V2.1 with V2.0 and you will easily see the differences.Alright, spent enough time on TicTacToe, time to move on to the next project....Source Code for TicTacToe V2.1 (Leaking Fix...

Tuesday, July 12, 2011

Open Source Game: TicTacToe Ver 2.00

After about a week's hard work, I finally merged TicTacToe Ver 1 with the multi-view switching project and created a updated version of TicTacToe called Ver 2.00 which has multiple view controllers. Some high level information as below.Instead of "everything in single main.m file" as in Ver 1, Ver 2 is splited into different files.There are total of 4 View Controllers. The main one only in charge of switching between the 3 child view controllers. The 3 child view controllers are Intro, GamePlay...

How to print BOOL in NSLog

Was trying various ways to dump the value of a BOOL in NSLog for debugging and couldn't get it to work properly. Did a quick search on the net and quickly found the solution as below, just convert it into a NSString!NSLog(@"isTwoPlayerMode=%@", ([currentGameData isTwoPlayerMode] ? @"YES" : @"NO"...

Tuesday, July 5, 2011

How to prevent the screen from sleeping

Learned how to prevent the screen from sleeping from Nick's SpaceBubble code, and his comment about AngryBirds is quite funny... // Prevent the screen from sleeping!  Important!!  (AngryBirds doesn't do this btw...annoying) [application setIdleTimerDisabled:YE...

What? Can't play any sound/music on iPhone simulator?

Was trying to test some sound/music but nothing worked. Checked the net and looks like it only works in the real device... Damn...Please let me know if any of you know how to get sound to work on simulator...[UPDATE] The content of this post is no longer valid, please see this post and many others which shows how to play sound/music/video in simulat...

Monday, July 4, 2011

Speedo Meter Test Project

I got this speedo meter test project working. It's quite interesting seeing the needle slowly moves to different positions when you clicked on any of the 4 buttons.Move #1 - 0 degreeMove #2 - 90 degreesMove #3 - 180 degreesMove #4 - 270 degreesBut would certainly need a lot more work to make it moves/trembles/shakes like a speedo meter in the car when you step on the accelerator....The needle image is from https://github.com/jfryman/velometerThe loadView method of the view controller only did...

Sunday, July 3, 2011

Multi-View switching Test Working!

Thanks to Nick's Space Bubble Source Code, I created this test NIB-less project with 4 simple views. As shown below, the Main one has 3 buttons, click on any of them will trigger the switch to one of the 3 child views - each have a different background colour, and only have one button to close the child view and return back to the main view.As the child view releases itself when the button been clicked, the main view didn't need to release each child views.Please let me know if you found any...

Open Source Game: TicTacToe Ver 1.00

Finally got ver 1.00 of my first game - TicTacToe completed. As usual, it's a NIB-less design. I have put everything in one "main.m" but it shouldn't be too difficult for you to split into separate files if required.Link to full source code listed below, I tried to make the code looks tidy and put in as many comments as possible within limited time. Drop me some comments on the blog or email me if you need any further info.Well, actually the 2 players mode has been fully working for a few days....

Page 1 of 66712345Next