简体   繁体   English

为什么iOS 5.0不像普通窗口应用程序? 为什么要求使用视图控制器?

[英]Why doesn’t iOS 5.0 like plain window applications? Why does it request that view controllers be used?

I have an iOS app that I created with Xcode 4.0's “Window-based Application” template. 我有一个iOS应用程序,我使用Xcode 4.0的“基于窗口的应用程序”模板创建。 It worked fine back then and it was using the iOS 4.3 SDK. 当时工作正常,它使用的是iOS 4.3 SDK。 This is an app that simply puts the buttons, labels, etc. directly onto a window. 这是一个简单地将按钮,标签等直接放在窗口上的应用程序。 No view controllers—no nothing. 没有视图控制器 - 没什么。

But now that I've upgraded to Xcode 4.2 (and its iOS 5.0 SDK), and I run the app, this message gets logged to the console when the app launches in the simulator: 但是现在我已经升级到Xcode 4.2(以及它的iOS 5.0 SDK),并且我运行了应用程序,当应用程序在模拟器中启动时,此消息会被记录到控制台:

“Applications are expected to have a root view controller at the end of application launch” “应用程序在应用程序启动结束时应该有一个根视图控制器”

To be sure, the app continues to work, but this rather bothersome log gets printed out on every launch. 可以肯定的是,该应用程序继续工作,但每次启动时都会打印出这个相当麻烦的日志。

Why is this happening? 为什么会这样? Why does iOS 5.0 prefer/request view controllers? 为什么iOS 5.0更喜欢/请求视图控制器?

I don't know specifically why the message is logged, but integration between UIWindow and UIViewController has been increasing over the last several iterations of iOS. 我不清楚具体记录消息的原因,但UIWindow和UIViewController之间的集成在iOS的最后几次迭代中一直在增加。 iOS 4 added a rootViewController property to UIWindow. iOS 4为UIWindow添加了一个rootViewController属性。 The two classes work together to manage view rotation. 这两个类一起管理视图旋转。 Given the new capabilities that iOS 5 introduced to UIViewController (specifically, the ability to create your own container view controllers), it's clear that the relationship between the two classes will continue to evolve. 鉴于iOS 5为UIViewController引入的新功能(特别是创建自己的容器视图控制器的能力),很明显两个类之间的关系将继续发展。 As you've said, your app continues to function in iOS 5, so having a root view controller isn't a hard and fast requirement yet. 正如您所说,您的应用程序将继续在iOS 5中运行,因此拥有根视图控制器并不是一项艰难而快速的要求。 Perhaps there are features planned for future iOS versions that will depend on having a view controller available. 也许有未来的iOS版本计划的功能将取决于可用的视图控制器。

I don't have anything against them, and I will use them if iOS wants me to. 我没有任何反对他们的东西,如果iOS要我,我会使用它们。 I was just curious about the above behavior. 我只是对上述行为感到好奇。

I'd interpret the logged message as a gentle but persistent nudge from Apple toward providing a root view controller. 我会将记录的消息解释为从Apple提供根视图控制器的温和而持久的推动。 Most apps already use view controllers anyway, so this isn't a big change, but there are probably a number of apps out there that don't properly set the window's rootViewController property to their top-level view controller. 大多数应用程序已经使用了视图控制器,所以这不是一个很大的改变,但是可能有很多应用程序没有正确地将窗口的rootViewController属性设置为它们的顶级视图控制器。

You have just Connected your "view" with "File Owner".....just remove that connection and run your app.click your view and see the connections inspector area and remove that connection which I told..I dont know exactly what reason..but i had this issue and i cleared. 您刚刚将“视图”与“文件所有者”连接起来.....只需删除该连接并运行您的app.click您的视图并查看连接检查器区域并删除我告诉过的那个连接。我不知道究竟是什么理由..但我有这个问题,我清除了。 May be you have used some tableview or some other views in it.So the app. 可能你已经使用了一些tableview或其他一些视图。所以应用程序。 needs a view controller to launch.If you remove that connection then it will run what you wrote in a code only... 需要一个视图控制器来启动。如果你删除了那个连接,那么它将运行你在代码中写的东西......

Let me tell you the reason. 我告诉你原因。

In former edition, Window-based Application is used to build multi-view applications.But in Xcode 4.2,the Window-based Application does not exist any more. 在以前的版本中,基于Window的应用程序用于构建多视图应用程序。但在Xcode 4.2中,基于Window的应用程序不再存在。 Empty Application is designed to establish a multi-view program. Empty Application旨在建立一个多视图程序。

The difference between Window-based Application and Empty Application is that the former has a main window, the MainWindow.xib. 基于Window的Application和Empty Application之间的区别在于前者有一个主窗口MainWindow.xib。

When the program starts, iPhone build the main window firstly. 程序启动时,iPhone首先构建主窗口。 The content in the MainWindow will be loaded and built.But if you want more functions, eg multi-view, you still have to new a root view controller. MainWindow中的内容将被加载和构建。但是如果你想要更多的功能,例如多视图,你仍然需要新的根视图控制器。 Root view controller can help manage the views in your program. 根视图控制器可以帮助管理程序中的视图。 In the new edition,Xcode 4.2, a root view controller is expected. 在新版本的Xcode 4.2中,需要一个根视图控制器。

In the new edition, there is not a MainWindow.xib in Empty Application.The AppDelegate create a window instead. 在新版本中,空应用程序中没有MainWindow.xib.AppDelegate会创建一个窗口。 And it wants a root view controller. 它需要一个根视图控制器。 So the best way is to create a UIViewController Subclass with XIB for interface for MainWindow. 因此,最好的方法是使用XIB为MainWindow创建一个UIViewController子类。 But in the old edition, XIB is not needed. 但在旧版本中,不需要XIB。

So get it? 那么明白吗? Without a root view controller, you are not going to receive an error, but you can hardly do any thing without one. 如果没有根视图控制器,您将不会收到错误,但如果没有错误,您几乎无法做任何事情。 That's why the warning always come out. 这就是警告总是出来的原因。

暂无
暂无

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

相关问题 为什么选项卡栏没有显示在我的视图控制器上? - Why doesn't the tab bar show up on my view controllers? iOS-为什么不显示表格视图? - iOS - Why table view doesn't show? 为什么iOS模拟器仅显示空白视图/窗口? - Why does the iOS Simulator show only a blank view/window? 为什么hitTest不返回附加到窗口的视图? - Why doesn't hitTest return the view attached to the window? 为什么我的普通UITableView节页脚在iOS 7中浮动在输入的附件视图上方? - Why does my plain UITableView section footer float above my input's accessory view in iOS 7? 为什么iOS在运行单元测试时不会调用我的视图控制器UITableViewDelegate方法? - Why does iOS not call my view controllers UITableViewDelegate methods when running a unit test? 当我单击IOS中的按钮时,为什么视图不显示? - Why the view doesn't show when I click the button in IOS? iOS:设置rootViewController不会删除显示的旧视图控制器 - iOS: Setting the rootViewController doesn't remove the old presented view controllers 为什么我的Web视图在ios中不显示webrtc摄像机? - Why does my webview doesn't show the webrtc camera in ios? iOS Swift-为什么图像视图没有出现在情节提要中的默认字幕样式TableCellView中,所以为什么它与标签不同 - IOS Swift - Why doesn't the image view appear in the default subtitle style TableCellView in the storyboard why is it different then the labels
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM