2013年8月8日 星期四

Storyboard

以前寫iOS app好多時都係用code 做transition 同埋data transfer 例如:

- (void) buttonTapped:(UIButton *) sender
{
NextViewController *nextVC = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
// presentModalViewController or pushViewController ...
}

presentModalViewController 就一個ViewController 上面加上另一個ViewController 當上面既ViewController 做完野就自己dismiss 返

pushViewController 就用係navigationController 有個stack maintain住前面既ViewController

拎住nextVC 可以set 佢既properties delegate variable etc.

係iOS 6 Xcode 多左 storyboard

目的係令到developer 可以更加清楚成個application 既flow 同時更容易同其他non-technical 人溝通

而係storyboard 只要set 好左既ViewController 既UI 同class 用control-drag 就連住唔同ViewController

係sourceViewController 既 .m 加上

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UIViewController *destination = segue.destinationViewController;
    //setting destinationVC property
    [destination setValue:@"someValue1" forKey:@"propertyName1"];
    [destination setValue:@"someValue2" forKey:@"propertyName2"];

    //use this to check if there is setter for a property
    if([destination responseToSelector:@selector(setPropertyName3:) ])
    {
   //prepare some temp object
   NSDictionary *someValueDict = @{"index" : "1" ,"object" : object };
   [destination setPropertyName3:someValueDict];
    }
}


沒有留言:

張貼留言