2

두 클래스가 있습니다. 말하자면 A, B 클래스. from class pushviewController가 호출되면 B 클래스가 나타납니다. 그런 다음 여기에 문제가 있습니다. 내가 B 클래스에서 popviewcontrolleranimated 메서드를 호출하면 A로 돌아가지만 두 클래스의 viewwillappear 메서드가 호출됩니다. 누구나 여기서 무슨 일이 일어나는지 말해 줄 수 있습니다. 나는 붙어있다!. 다음은 A 클래스입니다.popViewControllerAnimated가 뷰에 영향을 줍니까?

@implementation ShakeViewController 

- (id) init { 
if (self = [super init]) { 
    movieName = @"04"; 
    self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]; 
    [self.view setBackgroundColor:[UIColor whiteColor]]; 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shake_it.png"]]; 
    [self.view addSubview:imageView]; 
    [imageView release]; 
    nextController = [[OtsugeViewController alloc] init]; 
}  
return self; 
} 

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { 
const float violence = 1.2; 
static BOOL beenhere; 
BOOL shake = FALSE; 

if (beenhere) return; 
beenhere = TRUE; 

if (acceleration.x > violence || acceleration.x < (-1* violence)) 
    shake = TRUE; 
if (acceleration.y > violence || acceleration.y < (-1* violence)) 
    shake = TRUE; 
if (acceleration.z > violence || acceleration.z < (-1* violence)) 
    shake = TRUE; 
if (shake && mPlayerPushed) { 
    [self playSound:@"suzu"]; 

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"noVib"] == NO) { 
     AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); 
    } 

    [[UIAccelerometer sharedAccelerometer] setDelegate:nil]; 
    [self presentModalViewController:mMoviePlayer animated:YES]; 
    [self play]; 
    mPlayerPushed = YES; 
} 

beenhere = false; 
} 

- (void)toNext { 
NSLog(@"ShakeViewController:toNext"); 
[self.navigationController pushViewController:nextController animated:NO]; 
} 

- (void)viewWillAppear:(BOOL)animated { 
[super viewWillAppear:animated]; 
NSLog(@"Shake:viewWillAppear"); 
} 

- (void)viewDidAppear:(BOOL)animated{ 
[super viewDidAppear:animated]; 
[[UIAccelerometer sharedAccelerometer] setDelegate:self]; 
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:0.5]; 
} 

- (void)dealloc { 
[super dealloc]; 
} 

@end 

여기에 B 클래스

@implementation OtsugeViewController 

- (id) init { 
if (self = [super init]) { 
    movieName = @"03"; 
    self.view = [[[OtsugeView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]; 
} 
return self; 
} 

- (void) toNext { 
NSLog(@"OtsugeViewController:toNext"); 
[self.navigationController popViewControllerAnimated:NO]; 
} 

- (void) toToppage 
{ 
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];   

[self.navigationController popToRootViewControllerAnimated:NO]; 
} 

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
NSLog(@"Screen touch Otsuge View"); 
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                  delegate:self 
                 cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil 
               otherButtonTitles:@"Retry", @"Main Menu", nil]; 
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent; 

actionSheet.cancelButtonIndex = 0; 
[actionSheet showInView:self.view]; 
[actionSheet release]; 
} 

- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex 
{ 
switch (buttonIndex) { 
    case 0: // Retry 
     [self presentModalViewController:mMoviePlayer animated:YES]; 
     [self play]; 
     break; 
    case 1: // Main Menu 
     [self toToppage]; 
     break; 
    case 2: // Cancel 
     break; 
    default: 
     break; 
} 
} 

- (void) viewWillAppear:(BOOL)animated { 
mMoviePlayer.moviePlayer.backgroundView.backgroundColor = [UIColor blackColor]; 
[self playSound:@"taiko_1"]; 
NSLog(@"Otsuge:viewWillAppear"); 
[(OtsugeView *)self.view renewImageView]; 

[super viewWillAppear:animated]; 
} 

- (void) viewDidAppear:(BOOL)animated{ 
NSLog(@"Otsuge:viewDidAppear"); 
[super viewDidAppear:animated]; 
} 

- (void) dealloc { 
[super dealloc]; 
} 

@end 
+0

당신은 클래스 B에서 클래스 A로 팝을 한 후에 클래스 B viewWillAppear가 호출된다는 것을 의미합니까? B 클래스의 viewWillDisappear라고도합니다. – sergio

+0

예. viewwillappear는 pop을 한 후에 호출됩니다. viewwilldisappear에 대해 아무것도 변경하지 않았으므로 기본값입니다. –

답변

0

그것은 정상입니다. 보기가 나타날 때마다보기가 나타납니다. 처음 뷰가 표시 될 때만 메소드를 호출하려면 뷰 컨트롤러에서 스택의 각 뷰가 메모리에 보관되지만 팝업 뷰는 할당 취소됩니다.