Showing posts with label Question. Show all posts
Showing posts with label Question. Show all posts

Wednesday, September 12, 2012

Applications are expected to have a root view controller at the end of application launch

Was testing the example game that comes with Nextpeer, and found this line in the log:


2012-09-11 23:24:19.571 ExampleGame[9101:15b03] cocos2d: Frame interval: 1
2012-09-11 23:24:19.573 ExampleGame[9101:15b03] Using Nextpeer version (1.2.10). https://api.nextpeer.com/v2/sdk
2012-09-11 23:24:19.857 ExampleGame[9101:15b03] Applications are expected to have a root view controller at the end of application launch
2012-09-11 23:24:19.857 ExampleGame[9101:15b03] cocos2d: surface size: 320x480
2012-09-11 23:24:22.441 ExampleGame[9101:15b03] cocos2d: Frame interval: 15
2012-09-11 23:24:29.960 ExampleGame[9101:15b03] cocos2d: Frame interval: 1


As I never seen this before, asked Daniel/Nextpeer and he confirmed it's not related to Nextpeer, but rather "has to do with how Cocos2D manages the UIWindow and root view controller objects for game. Nothing too serious :)"

Just not sure is Cocos2D trying to tell us something is not right? Compared to my other code, it seems it's because there's no RootViewController been used in the AppDelegate that's causing this to happen. As the app still works perfectly - which proves that Cocos2D can run without a RootViewController, so we probably can ignore that.

Monday, January 16, 2012

How to upgrade from old Cocos2d projects?

I believe quite a few readers might have similar question like me - how to upgrade an old application with outdated Cocos2d to the latest version?

I was reading chapter 7 (scrolling with joy) of Cocos2d book. And the author uses "SneakyInput" as example to port it to a new Cocos2d project. All he did is create a new Cocos2d project, then copied a few classes over from the old one, and that's it? Since every project is different, it could be a lot more complicate for other projects... Will give that a try later...

Thursday, January 12, 2012

Interesting example of 2 dimensional array in CCArray - to "alloc" or not?

I was reading Learn cocos2d Game Development with iOS 5 by Steffen Itterheim. There's something quite interesting in chapter 8 which I tried a few times but still don't quite get it.

There's this piece of code (Listing 8-7) which I will only list part of it here:

-(void) initEnemies
{
  enemies = [[CCArray alloc] initWithCapacity:EnemyType_MAX];

  for (int i = 0; i < EnemyType_MAX; i++)
  {
    .....


    CCArray* enemiesOfType = [CCArray arrayWithCapacity:capacity];
    [enemies addObject:enemiesOfType];
  }
}


-(void) dealloc
{
  [enemies release];
  [super dealloc];
}

The explanation is as below:

The interesting part here is that the CCArray* enemies itself contains more CCArray* objects, one per enemy type. It’s what’s called a two-dimensional array. The member variable enemies requires the use of alloc, because otherwise its memory would be freed after leaving the initEnemies method. In contrast, the CCArray* objects added to the enemies CCArray do not need to be created using alloc, because the enemies CCArray retains the objects added to it.


To make the whole thing clearer, the declaration of "enemies" is in the header file (Listing 8-6) as below:

#import "cocos2d.h"
@interface EnemyCache : CCNode
{

  CCArray* enemies;
}
@end

But I thought if "initEnemies" was called, then as long as the EnemyCache class doesn't get released, the member variable enemies should always exist isn't it? Confused... Might try to post it in Steffen's forum...

Monday, November 21, 2011

Things learned from "iLabyrinth"

Was reading the code of iLabyrinth game by UD7 Studios and learned quite a few things worth written down even though only looked at a few files:

1)The way they handle the loading of different sprite/map files according to different device/resolution:


2) The "isDeviceIPad()" is a macro defined as below for detecting if the device is an iPad, very handy.

static BOOL isDeviceIPad(){
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
    if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
        return YES;
    }
#endif
    return NO;
}

3) The "hightRes()" part (shouldn't it be "highRes()" :-) ?) also worth a look, probably to differentiate between devices like iPhone 4 which has higher resolution from previous devices.

+ (BOOL)hightRes {
    if( [[CCDirector sharedDirector] contentScaleFactor] > 1 ){
        return YES;
    }
    
    return isDeviceIPad();
}

4) In my older projects, I always use lots of "#define" to define different game states, later learned to use "typedef enum" to just list out all of them and saved a lot of typing. Noticed as below they also assign each item a value using bit shift operation, which means may be these items can also be used for calculation/operation if required, which is quite cool.

typedef enum {
WalkPathWalk = 0,
WalkPathToTop   = 1 << 1,
WalkPathToRight = 1 << 2,
WalkPathToBottom= 1 << 3,
WalkPathToLeft  = 1 << 4,
WalkPathEntrance= 1 << 5,
WalkPathExit = 1 << 6,
WalkPathNoPath = 1 << 7,
} WalkPath;


typedef enum {
    ZeroPathToBottom= 1 << 7,
    ZeroPathToLeft  = 1 << 8,
    ZeroPathToTop   = 1 << 9,
    ZeroPathToRight = 1 << 10
} ZeroPath;


5) The way it handles game state saving is also new to me. It's called in "applicationDidEnterBackground" (shown below), "applicationWillResignActive" and "applicationWillTerminate" inside the AppDelegate code.

- (void)applicationDidEnterBackground:(UIApplication *)application {
[[CCDirector sharedDirector] stopAnimation];
[[CCDirector sharedDirector] pause];

// Save GameState
[NSKeyedArchiver archiveRootObject:[iLabyrinth sharedInstance] toFile:[iLabyrinth stateFile]];
}

6) Also a bit unclear about the concept of "Scene" and "Layer" at the moment, specially about how they interact with each other.

At first look, the game seems to only have one file called "UDGameLayer" which indicates it's a "Layer". But when I looked further down the code, inside quite a few "Scene" files (e.g. "UDGameEndScene.h" shown below), it actually includes a layer too.... hmmm.... that's a bit confusing...


@interface UDGameEndScene : CCScene {

}

@end


@interface UDGameEndLayer : CCLayer {
CCSpriteBatchNode *_backgroundLayer;
}

@end

7)This multiple build targets thing - already seen it in the Cocos2D sample project, but still worth mentioning and hopefully can later work out how to do it myself.

---------------------------------------------------

There's also a few other things I am still not very clear with Cocos2D and still looking for answers and trying to work out how it's been handled in iLabyrinth...

a) the concept of "storing multiple Sprites inside one big image file and then load the required part accordingly", specially if there's animation involved for each sprite.

b) the best way to structure the code if there's a main character (with different weapons?) and multiple levels to play - probably with different enemies/targets to fight with in each level.

Still lots of things to learn :-( ....

Monday, November 14, 2011

Strange error in Xcode 3.2.3 "texture_ undeclared"

While still working on the project, I copied the "Dice in Cup" project (with Cocos2D 1.0.1 and named "Cocos2dDiceInCup") from my MacBook Pro (which the project runs perfectly with Xcode 4.2/OS X 10.7.2) to a test VMWare box running Xcode 3.2.3 on OS X 10.6.4, strangely it won't compile at all. As shown below, keep complaining about "texture_ undeclared" error.

If I right click on "texture_" and select "Jump to Definition", as below you can clearly see "texture_" is properly defined in CCSprite.h", very strange...

I later copied the project to another box with Xcode 4.0/OS X 10.6.7 and it runs perfectly. May be Xcode 3.2.3 is just too old?

Also tried searching the net but can't anything relevant.

Monday, October 31, 2011

What's the benefit of having 2 names for the same variable?

I was following this tutorial called Cocos2d Sprite Tutorial, and noticed as below, the variables were first declared in the header file with an extra "_" underscore character at the front.

    CCSprite *_dragon;
    CCAction *_flyAction;
    CCAction *_moveAction;

But then at the @property declaration, the underscore character was removed.

@property (nonatomic, retain) CCSprite *dragon;
@property (nonatomic, retain) CCAction *flyAction;
@property (nonatomic, retain) CCAction *moveAction;

And then in the main ".m" file, both names were used as below with the "=" sign at the "@synthesize".

@synthesize dragon = _dragon;
@synthesize moveAction = _moveAction;
@synthesize flyAction = _flyAction;

And also inside the code both names were referenced as shown below:

        self.dragon = [CCSprite spriteWithSpriteFrame:frame1];
        _dragon.position = ccp( s.width/2-80, s.height/2);

But why? This is the not the first time I saw people doing that, but I don't understand the benefit at all, won't it be very confusing having 2 names for the same variable?

Monday, September 5, 2011

Instrument 4.1 (Build 4138)/ Xcode 4.1 (Build 4B110) still hung when profiling Project from Apple on OS X 10.7 Lion

I was thinking, may be it's my code - won't be too surprise if a project written by newbie like me causing problems isn't it?

Ok, so I then tried this "AlternateView" sample code from Apple, and guess what? It hung too!! Ha ha, that makes me feel much better...

Tried to search Internet and found this post on stack overflow.com about similar issue.

It also talks about starting up Instrument first, then switch back to Xcode to do profiling. I was able to get it working once, and then it stops responding again....

This is very painful, will wait for Apple to fix it then. Before that, will have to do all my profiling on the 10.6.7 box...

Problem with Instrument 4.1 (Build 4138)/ Xcode 4.1 (Build 4B110) running on Lion OS X 10.7?

I was testing my new "Memorise Me If You Can" game on my new 13" MacBook Pro running Lion OS X 10.7 using the Instrument/XCode 4.1. Noticed whenever I started Instrument it just hung and I wasn't able to stop or quit or pause it. Only way to stop is "Force Quite" which is quite annoying.

Wonder if any one experiencing same problem? I then run the same thing on another OS X 10.6.7 with Instrument/XCode 4.0, it works perfectly without any problem. I can stop or quite at any time.

I have posted 2 videos as below, 1st from 10.6.7 with Instrument/XCode 4.0, the 2nd one from 10.7 with Instrument 4.1 (Build 4138)/ Xcode 4.1 (Build 4B110).



Sunday, August 14, 2011

Open Source Game: Simple Ball Bouncing Game Ver 2

I expanded the simple ball bouncing game a bit. It now has a few more functions:
-added game pause function
-added left/right direction movement, toggle between up/left-right movement with direction button
-starts with 1 ball, get extra ball every 100 points (max 5 balls)
-added device rotation handling
-added top score recording using application preference

A simple video of the game is below:


Also learned some new skills, this is my first project with proper device rotation handling (using empty NIB design as the NIB-less design still have problem with rotation handling), and also my first project with saving data in application preference.

For example: I was following the instructions from chapter 7 of "Beginning iOS 4 application Development" for device rotation handling. But found that if I use "willAnimateSecondHalfOfRotationFromInterfaceOrientation" I keep getting this strange message shown below and the program will stop after running for a while: "Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations."

Don't know what the hell is "two-stage rotation animation", but after a few searches on the net, I fixed it by replacing the "willAnimateSecondHalfOfRotationFromInterfaceOrientation" function with "willAnimateRotationToInterfaceOrientation".

The source code available here

Wednesday, August 10, 2011

When can we have XCode Running on iPhone/iPad?

Was thinking, now that the iPhone/iPad devices are getting more powerful in every generation, wonder how long will it take before Apple release a "portable/mobile" version of XCode that runs on iPhone/iPad? In that case, we can all do development on the same device, how cool is that?

Saturday, August 6, 2011

Can't have array in @property?

Was following this You Tube Video "Making a simple iPhone game, part 2 by TheEagle1100 (DBaird Software), but I tried to do it in slightly different way. Instead of declaring 5 UIImageView calling them "*platform1" to "*platform5", I used an array to save the effort of duplicating.

However when I put in declaration for @property as below, as shown in screen dump above I get 2 errors. 1st about "Property cannot have array or function type 'UIImageView *[5]", the 2nd one says "Property with 'retain' attribute must be of object type.

@property (nonatomic, retain) IBOutlet UIImageView *platform[5];

If I remove the "retain" it will get rid of the 2nd error, but the first error remains....

Based on my "limited" understanding of how "@property" works, it's mainly for the getter and setters, so may be I have to write my own getter/setter or try some other way...

Friday, August 5, 2011

Why my NIB-less projects won't auto-rotate?

Found a problem with the NIB-less projects I have created so far. For some unknown reason, it won't auto-rotate? That is, if I create a simple NIB-less project with only 1 button and 1 label, and then rotate the simulator to either direction, then even if I change the "shouldAutorotateToInterfaceOrientation" as below to always return "YES", it won't move at all?


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return YES;
}


However, if I create another new project with NIB and create same button, label and same change to "shouldAutorotateToInterfaceOrientation" as above, both the button and label rotates nicely, why???

Very strange... Tried using the "nib2objc" tool to analysis the XIB file and it dumps lots of info about the view shown below, but still couldn't work out which property/attribute should be copied over to NIB-less version to make it auto-rotate... I am stuck :-( !!!


UIView *view6 = [[UIView alloc] initWithFrame:CGRectMake(0.0, 20.0, 320.0, 460.0)];
view6.frame = CGRectMake(0.0, 20.0, 320.0, 460.0);
view6.alpha = 1.000;
view6.alphaValue = // unknown property: 1;
view6.autoresizesSubviews = YES;
view6.autoresizesSubviewsForDevice = // unknown property: 1;
view6.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
view6.backgroundColor = [UIColor colorWithWhite:0.750 alpha:1.000];
view6.backgroundFilters = // unknown property: (
);
view6.canDrawConcurrently = // unknown property: 0;
view6.clearsContextBeforeDrawing = NO;
view6.clipsSubviews = // unknown property: 0;
view6.clipsToBounds = NO;
view6.contentFilters = // unknown property: (
);
view6.contentMode = UIViewContentModeScaleToFill;
view6.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}");
view6.focusRingType = // unknown property: 0;
view6.frameCenterRotation = // unknown property: 0;
view6.frameOrigin = // unknown property: {0, 20};
view6.frameSize = // unknown property: {320, 460};
view6.hidden = NO;
view6.ibExternalIdentityShowNotesWithSelection = // unknown property: 0;
view6.multipleTouchEnabled = NO;
view6.opaque = YES;
view6.opaqueForDevice = // unknown property: 1;
view6.simulatedOrientationMetrics = // unknown property: [This value is not printable by ibtool (IBUISimulatedOrientationMetrics)];
view6.simulatedStatusBarMetrics = // unknown property: [This value is not printable by ibtool (IBUISimulatedStatusBarMetrics)];
view6.tag = 0;
view6.userInteractionEnabled = YES;
view6.wantsLayer = // unknown property: 0;


Wednesday, July 27, 2011

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' />"
    "<script type='text/javascript' src='http://www.mathjax.org/wp-includes/js/l10n.js?ver=20101110'></script>"
    "<script type='text/javascript' src='http://www.mathjax.org/wp-content/plugins/syntax-highlighter-mt/scripts/shCore.js'></script>"
    "<script type='text/javascript' src='http://www.mathjax.org/wp-content/plugins/syntax-highlighter-mt/scripts/shAutoloader.js'></script>"
    "<link type='text/css' rel='stylesheet' href='http://www.mathjax.org/wp-content/plugins/syntax-highlighter-mt/styles/shCore.css'/>"
    "<link type='text/css' rel='stylesheet' href='http://www.mathjax.org/wp-content/plugins/syntax-highlighter-mt/styles/shThemeDefault.css'/>"
    "<style type='text/css'>body { background-color: #d2d3d3; }</style>"
    "<script type='text/x-mathjax-config'>"
    "MathJax.Hub.Config({ MMLorHTML: { prefer: {Firefox: \"HTML\"} } });"
    "</script>"
    "<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/1.1-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full'></script>"
    "</head>"
    "<body>";
    
    NSString *foo2 = [foo stringByAppendingString:strContent];
    NSString *foo3 = [foo2 stringByAppendingString:@"</body></html>"];


Then in the main file, it's loaded into an UIWebView, with the content (also extracted from same test page).


    NSString *fName = @"test1.html";
    
    NSString *xContent = @"<p>\\["
      "\\left( \\sum_{k=1}^n a_k b_k \\right)^{\\!\\!2} \\leq"
      "\\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)"
      "\\]</p>"
      "<BR/>"
      "<p>\\["
      "\\frac{1}{(\\sqrt{\\phi \\sqrt{5}}-\\phi) e^{\\frac25 \\pi}} ="
      "1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {1+\\frac{e^{-6\\pi}}"
      "|{1+\\frac{e^{-8\\pi}} {1+\\ldots} } } }"
      "\\]</p>";
    
    //write to temp file first
    [self writeStringToFile:tempDir fileName:fName content:xContent];
  
    //create UIWebView
    CGRect webRect = CGRectMake(10,10,300,400);
    myWebView =[[UIWebView alloc] initWithFrame:webRect];
    myWebView.scalesPageToFit = YES;
    myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
myWebView.delegate = self;
        
    NSString *path4 = [tempDir stringByAppendingPathComponent:fName];
     
    NSURL* url = [NSURL fileURLWithPath:path4]; 
    NSURLRequest* req = [[NSURLRequest alloc] initWithURL:url]; 
    [myWebView loadRequest:req];
    [self.view addSubview:myWebView];
    [req release];
  
    activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
activityIndicator.center = self.view.center;
[self.view addSubview: activityIndicator];

Unfortunately, I don't know how to include the whole MathJax into the project yet (the size is 16MB even after compressed into .ZIP file!!!), so although the HTML is first written to local temp directory then loaded back, it still has to go out through Internet to load those .JS files - which might not be the best solution for "off-line" mode operation I guess.

The source project is available below. Note that for the content you have to change every "\" into "\\" otherwise it won't work as that's the escape character.


Source for UIWebViewTest

[Update 1] After tested from local directory, found that to have the whole MathJax fully functioning, you need:
(1) the main "MathJax.js" file, plus
(2) all the files under the 4 sub-directories: "config", "extensions", "fonts" and "jax".
Just that "fonts" one by itself is more than 10MB in size!
Definitely much easier to get everything from Internet then...

[Update 2] Further test shows that as below, the "*foo" can be even further simplified by removing some of the settings in the middle (about 9 lines) and it still works ok (Note: only tested in Safari 5.0.5).

    NSString *foo = @"<html><head><meta name='viewport' content='initial-scale=1.0' />"
    "<script type='text/javascript' src='http://cdn.mathjax.org/mathjax/1.1-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full'></script>"
    "</head>"
    "<body>";

[Update 3] In case you wonder what does the following META tag mean, I will cover that in a separate post.
 "<meta name='viewport' content='initial-scale=1.0' />" 

[Update 4 (26/02/2012)] Please have a look at this new post about how to setup MathJax "Locally".

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 beginners like me... Might have to park this idea for a while...

[UPDATE 2] Please see this post of mine which I got it working in a UIWebView.

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>" tags, which are defined as below and doesn't seem to be unusual?


code, span.monospace {
font-family:Courier, monospace;
font-size:12px;
}

Not sure if this has anything to do with the printer or is it the CSS on the site. It's just not user friendly... Unless the author did that on purpose to stop people form printing their web pages - which I doubt it...


Any way, I learned 2 new things from that page:
(1) there's this tool called nib2objc which can convert NIB files into Objective-C, and 
(2) this free drawing tool called Inkscape
Will definitely give both of them a try!

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, what about "greenSlider" and "blueSlider", don't they also have to be called?

Also this part about "setFrame" too...

- (void)setFrame:(CGRect)rect

Still got a lot more stuffs to learn...Now where was I? Got lost again... back to the schedule...

Wednesday, July 13, 2011

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 each method been called, and removed that "ScratchTicketViewController" completely. The code still works! What the....

This is totally different from what I learned so far - so we can have a application that has no UIViewController at all, very interesting!

Next, I tried to add an UIView and an UIViewController to the project and compare the differences.

For UIView, as below it only has 3 methods, and one of them - "drawRect" disabled -- I remember seeing that name in previous Quartz 2D test project. I guess if you need any other methods, can still be triggered from the "initWithFrame" method.


@implementation UIView1

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)dealloc
{
    [super dealloc];
}

@end

However, for UIViewController it's a lot more complicate. As below there are a few extra ones: "loadView", "viewDidLoad", "viewDidUnload", "didReceiveMemoryWarning" and "shouldAutorotateToInterfaceOrientation". Which is definitely more complicate and powerful than the simple UIView above.

@implementation UIViewController1

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

I guess it all depends on the purpose of the code, if it's just a simple test project/application, which you don't care whether there's orientation change or memory warning or use NIB files, a simple UIView should be sufficient. For a more "normal", "fully functioning" project/application which is to be submitted to App Store, you would definitely still have to use UIViewController.

Ah! Feels good to learn new things everyday!

Tuesday, June 28, 2011

Question: What does this "^" symbol mean?

Saw a few tutorials (e.g. this one from the App Code Blog) using this "new" method for animation that works only on iOS4 and above... Don't quite understand what the hell does that "^" symbol mean.... Looks like still got lots of things to learn...


    [UIView animateWithDuration:0.5 delay:0.0 options: UIViewAnimationCurveEaseOut
                     animations:^
     {
         navigationBar.frame = navBarFrame;
     }
                     completion:^(BOOL finished)
     {
         NSLog(@"Done!");
     }
     ];