我是iOS編程新手。我創建視圖控制器具有的MKMapView元素,我想設置委託[mapView setDelegate:self]
將代理設置爲MKMapView
首先,我的方法initWithNibName了這事包:喜歡:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[[self map] setDelegate:self]];
UITabBarItem *item = [[UITabBarItem alloc] init];
[item setTitle:@"Map"];
[self setTabBarItem:item];
}
return self;
}
在這種情況下的MKMapView沒有給我任何消息,但當我將設置代理消息放置到viewDidLoad
方法時,它工作正常。
有人可以解釋爲什麼它不工作時setting delegate message
在initWithNibName:bundle
?
Tnx很多。所以現在我知道何時viewcontroller對象被初始化=) –