[iOS] 用 UIImagePickerController 從 相片庫挑選一張照片來顯示片段碼 , UIImagePickerControllerSourceTypeSavedPhotosAlbum , didFinishPickingMediaWithInfo ,

.h檔: 要加

@interface ViewController : UIViewController

 

.m 檔:

.
.
.

    
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    picker.allowsEditing = YES;

    [self presentViewController:picker animated:YES completion:nil];

    
    resultBox.text = @"Hello World!";
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
    [self dismissViewControllerAnimated:YES completion:nil];

    NSLog(@"\nin didFinishPickingMediaWithInfo\n");
    imgBox.image = [info objectForKey:UIImagePickerControllerOriginalImage];

}

Continue reading [iOS] 用 UIImagePickerController 從 相片庫挑選一張照片來顯示片段碼 , UIImagePickerControllerSourceTypeSavedPhotosAlbum , didFinishPickingMediaWithInfo ,

[iOS] Objective-C , block 寫法

螢幕快照 2014 03 05 下午12 37 49

在新的iOS API中block被大量用來取代傳統的delegate和callback,而新的API會大量使用block主要是基於以下兩個原因:

可以直接在程式碼中撰寫等會要接著執行的程式,直接將程式碼變成函數的參數傳入函數中,這是新API最常使用block的地方。 可以存取區域變數,在傳統的callback實作時,若想要存取區域變數得將變數封裝成結構才能使用,而block則是可以很方便地直接存取區域變數。

螢幕快照 2014 03 05 下午3 00 49螢幕快照 2014 03 05 下午3 35 41 螢幕快照 2014 03 05 下午5 43 02 螢幕快照 2014 03 05 下午7 29 09

 

螢幕快照 2014 03 05 下午6 11 37

Objective C Blocks: Summary, Syntax & Best Practices 

http://amattn.com/p/objective_c_blocks_summary_syntax_best_practices.html

 

 

Continue reading [iOS] Objective-C , block 寫法