顯示具有 iOS Course 標籤的文章。 顯示所有文章
顯示具有 iOS Course 標籤的文章。 顯示所有文章

2014年5月25日 星期日

[Cocos2DX] shakeAnimation

Shake Animation

2014年1月23日 星期四

[Cocos2Dx] Layer to disable all touch events

example 1
example 2
example 3

2012年6月4日 星期一

2012年3月11日 星期日

[iOS] UIAlertView

UIAlert View with multiple options.

in .h: include UIAlertViewDelegate


@interface MyController : UIViewController <UIAlertViewDelegate> {
}

in .m: implement delegate for UIAlertViewDelegate


#pragma UIAlertView
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"%d", buttonIndex);

[iOS] UIActionSheet

UIActionSheet Class Reference
Move Cancel Button from top to bottom

In .h: include UIAlertViewDelegate

@interface MyController : UIViewController <UIAlertViewDelegate> {
}


In .m: implement delegates

- (void) ShowActionSheet:(NSString *)title {
    UIActionSheet *actionSheet = [[UIActionSheet alloc] 
                                  initWithTitle:title
                                  delegate:self
                                  cancelButtonTitle:nil
                                  destructiveButtonTitle:nil 
                                  otherButtonTitles: nil];
    
    [actionSheet addButtonWithTitle:@"Option 1"];
    [actionSheet addButtonWithTitle:@"Option 2"];
    [actionSheet addButtonWithTitle:@"Option 3"];

    [actionSheet addButtonWithTitle:@"Cancel"];
    actionSheet.cancelButtonIndex = actionSheet.numberOfButtons;
    
    [actionSheet showInView:self.view];
    [actionSheet release];
}

- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"title=%@, buttonIndex: %d, cancelButtonIndex: %d, firstOtherButtonIndex: %d",
          actionSheet.title,
          buttonIndex, 
          actionSheet.cancelButtonIndex, 
          actionSheet.firstOtherButtonIndex);
}


2012年2月17日 星期五

[iOS] Class 1: NSArray, NSMutableArray, NSDictionary, NSMutableDictionary

NSArray

1. Can contain different variable types.
2. Contents of array cannot be modified. (add, remove and sort)

Create NSArray
NSArray *bookList = [NSArray arrayWithObjects: @"iPhone4", @"iOS", @"MacX", nil];

Add an empty object
[NSNull null]

Retrieve NSArray
NSArray *bookList = [NSArray arrayWithObjects:@"Moby", @"Frank", @"Tom", nil];
for (int y=0; y < bookList.count, y++) {
    NSLog (@"Book Title is %@", [bookList objectAtIndex:y])
}
result:
Book Title is Moby
Book Title is Frank
Book Title is Tom


NSMutableArray
1. Similar to NSArray.
2. Contents of array can be modified. (add, remove and sort)

Create NSMutableArray
NSMutableArray *bookList = [NSArray arrayWithObjects:@"iPhone4", @"iOS", @"MacX", nil];

Add an object (append to the end of the bookList)
[bookList addObject:@"New book"];

Insert an object at an specific place "index".
[bookList insertObject:@"New book" atIndex:index];

Remove an object at "index".
[bookList removeObject:index];

Sort Array: in alphabetical order
[bookList sortUsingSelector:@selector(caseInsensitiveCompare:)];


NSDictionary

1. Cannot be modified. (add, remove and sort)

Create NSDictionary
NSDictionary *book = [NSDictionary dictionaryWithObjectsAndKeys:
                                      @"a", @"1",
                                      @"b", @"2",
                                      @"c", @"3",
                                      @"d", @"4",
                                      @"e", @"5",
                                       nil];

Retrieve Object
[book objectForKey: @"1"];

NSMutableDictionary
1. Can be modified. (add, remove and sort)

Create NSMutableDictionary
NSMutableDictionary *book = [NSDictionary dictionaryWithObjectsAndKeys:
                                                  @"a", @"1",
                                                  @"b", @"2",
                                                  @"c", @"3",
                                                  @"d", @"4",
                                                  @"e", @"5",
                                                   nil];

Add an object
[book setObject: @"Value" forKey: @"KeyIndex"];