作者istale (一天一次的叹息,快用光ꜩ
看板MacDev
标题[问题] self的指向
时间Sun May 9 17:00:20 2010
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
1F:→ leondemon:an instance of myViewController 05/09 17:10
2F:→ uranusjr:self 指的是那个 instance 本身, 就你的程式码而言因为是 05/09 18:38
3F:→ uranusjr:HelloWorld_iPhoneAppDelegate 这个 class 里的 self, 所 05/09 18:38
4F:→ uranusjr:以是那个属於 HelloWorld_iPhoneAppDelegate 的 instance 05/09 18:38
5F:→ uranusjr:自己本身. 另外这诡异的 class naming 是打哪来的... 05/09 18:39
6F:→ leondemon:我没仔细看类别名 的确是HelloWorld_iPhoneAppDelegate 05/09 19:02
7F:→ leondemon:的instance 05/09 19:03
8F:推 aecho:self就相当於C++中的this 05/14 23:01