2011-07-29 69 views
0

我試圖在兩個視圖之間切換。問題在於它如何被調用。從該類中的方法調用中移除超級視圖

繼承人的最簡單的方法來解釋我的情況:

我有一個父視圖。 使用包含一個表的子類ChildView。 在該表中選擇一個對象後,我希望切換到該父視圖的不同子視圖。

父--------- |子1 | 2兒童

兒童1是父的子類,以允許我在父該子視圖1和2之間切換的訪問的方法,但由於某種原因,它不會工作時訪問它從兒童1.

任何線索如何做到這一點?繼承人的基本代碼:

兒童1 - (無效)changeViews

[super methodToSwitchChildViews]; 

家長 - (無效)methodToSwitchViews

[self.child1.view removeFromSuperView]; 
[self.view insertSubView:child2.view atindex:0]; 
+0

你這是什麼意味着你的孩子是你父母的一個子類?這隻意味着孩子擁有父母的財產,而不是與父母有聯繫。 – Cyprian

回答

0

好的,我挖了很多,終於想出了一個解決方案。如果有人曾經在這裏有同樣的問題,就是你要做的:

在子視圖的.h文件做

@class parentViewName 

然後在.m文件添加

#import "parentViewName.h" 

... 

- (void) functionToRemoveSelfFromView { 
    parentViewName *PARENT = [[parentViewName alloc] init]; 

    // You must have a method in the parent view to toggle or remove the subview, the way 
    // you want it done, then call it with the new delegate. Make sure it doesn't set this 
    // view to nil or releases it because this method has yet to return. If animating do not 
    // hide this view either. 

    [PARENT methodToRemoveSelfFromView]; 
    [PARENT release]; 
} 
0

超是先於類(子)類繼承。這裏的孩子似乎是對超級觀點(父母)的看法。所以使用superview,而不是超級。

相關問題