2014-07-07 24 views
0

我有一個NSAlert在XCode5如何assing一個@selector內的自定義方法XCode5

NSAlert *alert = [[NSAlert alloc] init]; 

    [alert setMessageText:@"Notificación"]; 
    [alert setInformativeText:mensaje]; 
    [alert setAlertStyle:NSInformationalAlertStyle]; 
    [alert beginSheetModalForWindow:window modalDelegate:nil 
        didEndSelector:@selector(myMethod}) 
         contextInfo:nil]; 

,你看到didEndSelector我有一個部分添加的方法,是可以自定義的內部創建有製作只是一個動作,比如像這樣

[alert beginSheetModalForWindow:window modalDelegate:nil 
        didEndSelector:@selector(myCustomMethod{NSLog(@"hola");}) 
         contextInfo:nil]; 

這是節約加入萬噸的方法爲每個NSAlert

感謝的時間提前了個方法電子書支持

回答

0

創建分離方法有一些的NSLog例如

- (void)logs { 
    NSLog(@"lalalalalal") 
} 

然後將其發送給選擇:

@selector(logs) 

如果你的方法得到了一些變化,你的選擇應該是這樣的:

@selector(logs:) 
+0

我想要的是避免單獨創建方法,因爲我有很多NSAlerts,所以我想聲明t他在每個NSAlert內部的方法,有沒有辦法做到這一點? – Jesus

+0

你想讓你的代碼不可讀?或者閱讀選擇器語法 – Anton

相關問題