2016-08-12 4 views
1

私はUIViewControllerを実行時に持っています。私はそのビューコントローラにビューを追加しますProgrammatically.Now私はそのビューコントローラのビュー階層を他のビューコントローラから印刷したいと思います。私はそれがview.It私はそれがどのようにdetails.Pleaseが私を示唆しているビュー&フレームのアドレスのみを行うことができます印刷物の正確な名前を印刷したいそして、この他のView ControllerからView Controllerの詳細を含むView階層を取得するにはどうすればいいですか?

UIView *main_view=[UiView alloc]initwithFrame:CGRectMake(20,20,34,80)]; 

のようなビューが追加されましたか?

+0

?ビューには名前がありません。 – rmaddy

+0

「正確な名前」が必要なときは、正確には – DAXaholic

+0

のUIView main_viewのインスタンスを作成したようなものを指定しなければなりません。main_view – Techiee

答えて

0

サブビューを再帰的に反復処理する必要があります。何名

- (void)listSubviewsOfView:(UIView *)view { 

    // Get the subviews of the view 
    NSArray *subviews = [view subviews]; 

    // Return if there are no subviews 
    if ([subviews count] == 0) return; // COUNT CHECK LINE 

    for (UIView *subview in subviews) { 

     // Do what you want to do with the subview 
     NSLog(@"%@", subview); 

     // List the subviews of subview 
     [self listSubviewsOfView:subview]; 
    } 
} 
0
//You can set unique tag to each subview and then when you fetch view the compare view tag and if it match with the particule tag, that will be the view for which you are looking for. 


UIView *main_view=[UiView alloc]initwithFrame:CGRectMake(20,20,34,80)]; 
main_view.tag = 1000; 
[self.view addSubView:main_view]; 



// fetch view 
UIView *view = [self.view viewWithTag:1000]; 
if (view.tag == 1000){ 
    NSLog("This is view - main_view"); 
} 
関連する問題