开发者

Is it possible to access UIView in MainWindow.xib using tag

开发者 https://www.devze.com 2023-02-04 13:14 出处:网络
There are 2 UIView in my MainWindow.Xib One is the outlet of RootViewController view, another UIView is that I hope to access using tag (123) from the source codes of RootViewController.

There are 2 UIView in my MainWindow.Xib One is the outlet of RootViewController view, another UIView is that I hope to access using tag (123) from the source codes of RootViewController. If the second UIView is the sub view of the first view, I know I can use

[self.view viewWithTag:123]; 

But I do not know how to handle this case when the UIView that hope to be accessed is not the sub view of current view.

Is it possible to access UIView in MainWindow.xib using tag

Welcome any com开发者_StackOverflow社区ment

Thanks

interdev


tag is specific to a UIView hierarchy (see Return value on UIView's viewWithTag:). Since there is no hierarchy between two separate views, you cannot use it.

Instead, do what phix23 suggests and add an IBOutlet for your second view in your RootViewController, i.e.:

RootViewController.h

@interface RootViewController : UIViewController {
  // ...
}

// @synthesize in RootViewController.m (don't forget to dealloc)
@property (nonatomic, retain) IBOutlet UIView *secondView;

Then hook that up in your XIB-file.

0

精彩评论

暂无评论...
验证码 换一张
取 消