简体   繁体   English

关于UIViews的非常简单的问题

[英]REALLY simple question about UIViews

I am working on an app that has several different views, two of the which are DetailViewController.h&.m and AddViewController.h&.m. 我正在开发一个具有多个不同视图的应用程序,其中两个是DetailViewController.h&.m和AddViewController.h&.m。 Neither of these particular view have IB xib files associated with them, they just have programmatically generated UITableViews. 这些特定视图均未与IB xib文件相关联,它们仅具有以编程方式生成的UITableViews。 These views essentially are the same, the only difference, is that in the AddViewController, you put info into cells, and in the DetailViewController that same info is viewable and editable. 这些视图本质上是相同的,唯一的区别是,在AddViewController中,您将信息放入了单元格,在DetailViewController中,相同的信息是可见的和可编辑的。 Essentially the viewDidLoad for the AddViewController overrides the DetailViewController viewDidLoad with different navigation bar items and title. 本质上,AddViewController的viewDidLoad会使用不同的导航栏项和标题覆盖DetailViewController的viewDidLoad。 MY QUESTION: Outside of IB, how do I reference which view I am in? 我的问题:在IB之外,如何引用我所处的视图? I want to have some switches and buttons available in the DetailView, that I don't want available in the AddView. 我想在DetailView中提供一些开关和按钮,而我不想在AddView中使用。 But being that as it is, they are refferencing the same info, and currently just changing the navigation bar items, they aren't seperate like I would like them to be. 但实际上,它们引用的是相同的信息,并且当前只是更改导航栏项目,它们并没有像我希望的那样独立。 Inside the DetailView viewDidLoad I'm thinking I need something where its like 在DetailView viewDidLoad内部,我想我需要像

if(currentView = DetailView) {
self.view addSubview: onOffSwitch;
}
else onOffSwitch. hidden = YES;

Or something to that effect. 或类似的东西。 Obviously if the above code actually worked, I wouldn't be writing this question :) Its probably just a syntax issue I can't hammer out, if you could please help me out, it would be greatly appreciated! 显然,如果上面的代码确实有效,我不会写这个问题:)它可能只是我无法解决的语法问题,如果您能帮助我,将不胜感激! Thanks 谢谢

Well there is similar question here 那么有类似的问题在这里

But for your case you can do it like: 但是对于您的情况,您可以这样做:

if([[self class] isKindOfClass:[DetailViewController class]]) {
self.view addSubview: onOffSwitch;
}
else 
onOffSwitch. hidden = YES;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM