带有 uinavigationcontroller 和 uitabbarcontroller 的 iPhone 应用程序

发布于 2024-12-02 14:41:04 字数 467 浏览 1 评论 0原文

我是 iPhone 编程新手,我正在尝试构建一个具有 uinavigationcontroller 的应用程序,而 rootviewcontroller 是一个 uiviewcontroller,它基本上是一个登录屏幕,用户从登录屏幕移动到 uitabbarcontroller,它有 5 个选项卡,每个选项卡都是一个uinavigationcontroller 和每个导航控制器在导航栏中都有两个按钮,一个按钮带来消息视图,另一个按钮带来通知视图,每个视图都是一个 uiviewcontroller。

现在用户可以按每个选项卡上的消息按钮,消息视图将会出现,我想确保如果他按下第一个选项卡上的按钮然后转到另一个选项卡,那么消息视图将会消失并从内存中释放,当他按下新选项卡上的消息按钮时,将出现另一个消息视图。

我尝试在应用程序委托中创建单个消息视图,每次用户按下消息按钮以从应用程序委托调用方法时,然后在方法中我检查按下了哪个选项卡并将视图推送到所属的导航控制器该选项卡但无法正常工作。

I'm new to iphone programming and i'm trying to build an application that has a uinavigationcontroller and the rootviewcontroller is a uiviewcontroller that is basicly a login screen from the login screen the user moves to uitabbarcontroller that has 5 tabs and each tab is a uinavigationcontroller and each navigationcontroller has two button in the navbar one button brings a messages view and the other notifications view each view is a uiviewcontroller.

Now the user can press the message button on every tab and the message view will appear and i want to make sure that if he presses the button on the first tab and then goes to another tab then the message view will disappear and deallocated from memory and when he presses the message button on the new tab then another message view will appear.

I tried the create a single message view in the app delegate and every time that the user presses the message button to call a method from app delegate then in the method i check which tab is pressed and push the view to the navigation controller that belongs to that tab but that doesn't work properly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒与心事 2024-12-09 14:41:04

您可以将登录视图嵌入 AppDelegate 中并根据需要显示它们。从那里您将加载 rootController,它应该是您的 tabBar。然后您可以在每个选项卡内加载导航控制器。每个选项卡一个。您可以从任何选项卡调用您的消息视图。只需确保以正确的方式分层控制器即可。

应用删除-->标签栏 -->导航控制器 -->个人观点

You can embed your login views inside the AppDelegate and show them as needed. From there you would load your rootController, which should be your tabBar. Then you can load up your navigation controller inside each tab. One for each tab. Your message view can be called from any of the tabs. Just need to make sure you layer your controllers the right way.

AppDel --> TabBar --> NavController --> Individual Views

月下凄凉 2024-12-09 14:41:04

您是否意识到可以替换窗口中的根视图控制器?您的应用程序委托的 -applicationDidFinishLaunching:withOptions: 方法可能会执行以下操作:

window.rootViewController = loginViewController;

当您设置窗口的 rootViewController 属性时,窗口将添加该视图控制器的视图作为其自身的子视图。

-applicationDidFinishLaunching:withOptions: 没有什么特别之处——它只是当应用程序完成加载并准备好开始工作时调用的委托方法。您可以像其他方法一样设置窗口的 rootViewController 属性,因此当您的登录视图控制器确定用户已成功登录时,它可以执行以下操作之一:

  • 实例化选项卡栏控制器并设置窗口的 rootViewController 属性本身
  • 向其委托发送一条消息(可能与应用程序委托是同一对象)以通知其登录成功;然后,代表可以安装标签栏控制器
  • 广播通知,告诉任何关心登录成功的人,并让其他人安装标签栏控制器

Do you realize that you can replace the root view controller in a window? Your app delegate's -applicationDidFinishLaunching:withOptions: method probably does something like:

window.rootViewController = loginViewController;

When you set the window's rootViewController property, the window will add that view controller's view as a subview of itself.

There's nothing particularly special about -applicationDidFinishLaunching:withOptions: -- it just happens to be the delegate method that's called when the app has finished loading and is ready to get down to business. You can set the window's rootViewController property just as well from other methods, so when your login view controller determines that the user has successfully logged in, it can do something like one of the following:

  • instantiate the tab bar controller and set the window's rootViewController property itself
  • send a message to its delegate (which would probably be the same object as the app delegate) to inform it that login was successful; the delegate could then install the tab bar controller
  • broadcast a notification to tell anyone who cares that login was successful, and let someone else install the tab bar controller
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文