2012-06-24 51 views
0

Newbee的問題在這裏 -目標C如何調用視圖控制器的方法從子視圖

我在視圖控制器M這個方法:

-(void) backToHP:(id<SwitchViewProtocol>) fromView{ 

    [(UIView *)self.currentView removeFromSuperview]; 
    [self.currentView clearView]; 
    [self.view addSubview:_hpView]; 
    self.currentView = nil; 

    CATransition *animation = [CATransition animation]; 
    [animation setDuration:0.2]; 
    [animation setType:kCATransitionPush]; 
    [animation setSubtype:kCATransitionFromLeft]; 
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 

    [[self.view layer] addAnimation:animation forKey:@"SwitchToView1"]; 
} 

我嘗試從一個子類調用它。 子類H:

@interface SetNotificationClass : UIView < SwitchViewProtocol> { 

    habitsViewController *hvc; 

} 

@property (nonatomic, retain) habitsViewController *hvc; 

子L:

@synthesize hvc; 

- (IBAction)saveNotificationClick:(id)sender { 
    // [self scheduleAlarm]; 
    [hvc backToHP:nil]; 
} 

我得到錯誤 「找不到方法」。任何想法?

感謝

+1

您應該使用委託並將您的hvc設置爲其子視圖的代表。 – shannoga

+0

什麼是'habitViewController'?我們需要查看代碼的其餘部分。 (另外,'方法未找到'編譯時或運行時錯誤?) – Vervious

回答

0

你在哪裏初始化HVC?你沒有發回backHP:沒有,對吧?我也可能只是將視圖控制器設置爲視圖的委託,而不是創建一個新的屬性。

+0

感謝您的提示 –

相關問題