看板 MacDev 關於我們 聯絡資訊
Delegate.h #import <UIKit/UIKit.h> @class MyViewController; @interface HelloWorld_iPhoneAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; MyViewController *myViewController; } @property (nonatomic,retain) IBOutlet UIWindow *window; @property (nonatomic,retain) MyViewController *myViewController; @end ------------------- Delegate.m #import "HelloWorld_iPhoneAppDelegate.h" #import "MyViewController.h" @implementation HelloWorld_iPhoneAppDelegate @synthesize window; @synthesize myViewController; - (void)applicationDidFinishLaunching:(UIApplication *)application { MyViewController *aViewController=[[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]]; [*[1;31mself setMyViewController:aViewController]; [aViewController release]; [window addSubview:[myViewController view]]; [window makeKeyAndVisible]; } ------------------------- 上面是xcode裡helloworld for iphone的sample code 我想問的是setMyViewController前的self, 從Delegate.h裡的宣告來看,這個self應該指myViewContorller 可是我用myViewController去替代self時,程式卻不能正確執行 那到底這個self指誰呢...謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.39.177.33
leondemon:an instance of myViewController 05/09 17:10
uranusjr:self 指的是那個 instance 本身, 就你的程式碼而言因為是 05/09 18:38
uranusjr:HelloWorld_iPhoneAppDelegate 這個 class 裡的 self, 所 05/09 18:38
uranusjr:以是那個屬於 HelloWorld_iPhoneAppDelegate 的 instance 05/09 18:38
uranusjr:自己本身. 另外這詭異的 class naming 是打哪來的... 05/09 18:39
leondemon:我沒仔細看類別名 的確是HelloWorld_iPhoneAppDelegate 05/09 19:02
leondemon:的instance 05/09 19:03
aecho:self就相當於C++中的this 05/14 23:01