내가 더 후 1 개 클래스의 객체를 사용하지만 하나 개의 클래스에 initWithNibName
를 사용하는 경우 내가의 getInstance :
static IGMapViewController *instance =nil;
+(IGMapViewController *)getInstance {
@synchronized(self) {
if (instance==nil) {
instance= [IGMapViewController new];
}
}
return instance;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// more code
instance = self;
}
return self;
}
이 클래스는 점에서
IGMapViewController
이름이있다.
init 메소드의 IGRouteController
클래스에서 _mapViewController = [IGMapViewController getInstance];
을 사용하면 initWithNibName
이 다른 클래스에서 실행되기 전에 발생합니다. IGRouteController
에서
은 내가 사용하는 방법 방법 updateRouteList
있습니다 : 그것은 모든 실행 않습니다
[_mapViewController drawSuggestedRoute:suggestedRoute];
을하지만 결과를 볼 수 없습니다.
은 내가 사용하는 경우 :
IGMapViewController *wtf = [IGMapViewController getInstance];
[wtf drawSuggestedRoute:suggestedRoute];
는 그럼 잘 작동 않습니다.
인스턴스와 초기화를 나중에 사용할 수 있습니까?
달성하려는 목표는 무엇입니까? –
인스턴스를 어딘가에 가져옵니다.initWithNib 및 make는 인스턴스를 initWithNib로 만든 인스턴스와 같게 만듭니다. – clankill3r
필자는보기 컨트롤러 싱글 톤을 사용하려고 시도한 앱을 사용해 보았습니다. 불쾌한데, 무엇을하려합니까? –