簡體   English   中英

從該類內部的方法調用中刪除超級視圖

[英]Removing a superview from a method call inside that class

我正在嘗試在兩個視圖之間切換。 問題是如何調用它。

這是解釋我的情況的最簡單方法:

我有家長意見。 對於子類ChildView,該子類包含一個表。 在該表中選擇一個對象后,我希望切換到該父視圖的另一個子視圖。

父母--------- |孩子1 |孩子2

子級1是父級的子類,允許我訪問父級中在子級視圖1和2之間切換的方法,但是由於某些原因,當從子級1訪問它時,它將無法工作。

有關如何執行此操作的任何線索? 這是基本代碼:

子1- (void)changeViews

[super methodToSwitchChildViews];

父級 -(void)methodToSwitchViews

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

Super是繼承中(子)類之前的類。 在這里,孩子似乎是超級視圖(父視圖)上的視圖。 因此,請使用超級視圖,而不是超級視圖。

好吧,我仔細研究了一下,終於找到了解決方案。 如果有人遇到相同的問題,請執行以下操作:

在子視圖的.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];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM