UIViewController
단추가있는 UIViewController
단추가 있습니다. 버튼을 클릭하면 내 NSLog
과 같이 표시되며 완료되면 다른 viewcontroller
을로드하라는 알림을 보내려고합니다. 글쎄, 모든 일이 올바르게 끝났다고해도, 어떻게 든 작동하지 않고 UIViewController
이 나타나지 않습니다. 여기 코드는 다음과 같습니다NSNotificationCenter 문제 및 UIViewControlletr로드
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(infoPage:)
name:@"InfoPage" object:nil ];
-(void) infoPage:(NSNotification*)notification
{
NSLog(@"Code executing in Thread %@",[NSThread currentThread]);
InfoCtrol *i = [[InfoCtrol alloc] init];
i.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:i animated:YES];
}
내 tabbaritem 버튼
-(void)info {
[[NSNotificationCenter defaultCenter] postNotificationName:@"InfoPage"
object:nil
userInfo:nil];
NSLog(@"test not");
}
내가 생각하는 내 문제가 있다는 것입니다 : 그것은 mainThread에 아니지만 난 그 해결 방법을 모르겠어요 :
을나는이를 사용하지만있는 UIViewController를 가져 오지 않았다
[self performSelectorOnMainThread:@selector(test) withObject:nil waitUntilDone:NO];
-(void)test{
[[NSNotificationCenter defaultCenter] postNotificationName:@"InfoPage"
object:nil
userInfo:nil];
}
난 그냥 버튼이 코드를 삽입하면, UIViewController
를 표시하지만 내가 사용하려는 NSNotificationCenter
InfoCtrol *i = [[InfoCtrol alloc] init];
i.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:i animated:YES];
내 로그인 :
Code executing in Thread <NSThread: 0x1fd7c7e0>{name = (null), num = 1}
업데이트 : 당신은 통지를 사용하려는 이유
How should i remove last thread from mainThread
모든 UIKit 작업은 주 스레드에서 발생합니다. 스레드를 사용하여 다른 스레드로 고의로 이동해야합니다. 그랜드 센트럴 파견 (Central Central Dispatch), 다른 스레드에 있다는 것은 문제가되지 않을 것입니다. 하지만,'NSThread'에'isMainThread'라고 불리는 클래스 메소드가 있습니다. – MaxGabriel
이 코드 스 니펫은 어떤 컨트롤러에 있습니까? 가지고있는 컨트롤러와이 코드가있는 곳을 설명해야합니다. – rdelmar
'self.navigationController'가'nil'이 아님을 확인하십시오 –