작은 프로젝트를 시작하여 NSViewController
주위에 머리를 들었습니다.NSViewController의 이상한 동작
AppController
은 NSOpenPanel
을 처리합니다. 무비 파일에 대한 URL을 얻은 후에는 NSViewController
서브 클래스 (NNMovieViewController
)로 전달합니다.
-(void)openMovieWithURL:(NSURL *)url {
NSError *error;
movie = [[QTMovie alloc] initWithURL:url error:&error];
[startButton setEnabled:YES];
[movieView setMovie:movie];
NSLog(@"button: %@", [startButton isEnabled][email protected]"YES":@"NO");
// logs "NO"
NSLog(@"movie: %@", movie);
// logs the correct movie object
NSLog(@"movieView: %@", [movieView movie]);
// logs "(null)"
}
헤더 파일은 다음과 같습니다 : 나는 무엇을 놓치고
#import <Cocoa/Cocoa.h>
#import <QTKit/QTKit.h>
@interface NNMovieViewController : NSViewController {
QTMovie *movie;
BOOL playing;
IBOutlet QTMovieView *movieView;
IBOutlet NSButton *startButton;
}
-(IBAction)clickStart:(id)sender;
-(void)openMovieWithURL:(NSURL*)url;
@end
이것은 내가 그것을 어떻게? 내가 Kreiri 및 Parag Bafna의 의견을 접수 한 후 다시 한 ... NSViewController
하고 그냥 일없이 프로젝트의 모든 것을
UPDATE
내가 만지작 조금 더 발견 그 시간에 나는 내 AppController 내부에 [movieViewController openMovieWithURL:url];
이라고 부르며 아웃렛은 아직 연결되지 않았다.
이 내 AppController가 구현 한 것입니다 :
#import "AppController.h"
@implementation AppController
@synthesize movieViewController;
- (void)awakeFromNib {
movieViewController = [[NNMovieViewController alloc] initWithNibName:@"NNMovieViewController" bundle:nil];
NSView *viewControllerView = [movieViewController view];
[view addSubview:viewControllerView];
}
- (IBAction)clickOpen:(id)sender {
NSOpenPanel *dialog = [NSOpenPanel openPanel];
[dialog setCanChooseFiles:TRUE];
[dialog setCanChooseDirectories:FALSE];
[dialog setAllowsMultipleSelection:FALSE];
[dialog setAllowedFileTypes:[QTMovie movieFileTypes:0]];
if ([dialog runModal] == NSOKButton) {
NSURL *movieFileURL = [[dialog URLs] objectAtIndex:0];
[self openMovie:movieFileURL];
}
}
- (void)openMovie:(NSURL *)url {
NSLog(@"startButton: %@", [movieViewController movieView]);
// logs "null"
NSLog(@"startButton: %@", [movieViewController startButton]);
// logs "null"
NSLog(@"---------------------------------");
[movieViewController openMovieWithURL:url];
}
@end
은 'movieView' nil입니까? – Kreiri
어디에서 movieView를 초기화하나요? –
흠. movieView는 콘센트이고 Interface Builder를 통해 연결되어 있습니다. 그러나 짐작할 수 있듯이 실제로 null입니다 (내 startButton과 마찬가지로). 어떻게해야합니까? – Wukerplank