gpt4 book ai didi

ios - 在 MonoTouch 中的 View Controller 之间切换

转载 作者:行者123 更新时间:2023-11-29 03:59:44 25 4
gpt4 key购买 nike

假设我的应用程序中有 4 个屏幕(iPhone View Controller ),我喜欢在它们之间导航。例如:

> 1 ----> 2
> 2 ----> 3
> 3 ----> 2 (With new data)
> 2 ----> 4
> 4 ----> 1

这当然只是一个例子,实现这一目标的正确方法是什么?

最佳答案

乌迪一世,

实现此类导航的正确方法是通过UINavigationController .来自苹果文档:

The UINavigationController class implements a specialized view controller that manages the navigation of hierarchical content. This navigation interface makes it possible to present your data efficiently and also makes it easier for the user to navigate that content. This class is generally used as-is but may be subclassed in iOS 6 and later.

以下 API 允许您在堆栈中导航

– pushViewController:animated:
– popViewControllerAnimated:
– popToRootViewControllerAnimated:
– popToViewController:animated:

如果您需要在 Controller 之间传递数据,只需像下面这样注入(inject)它们:

// within the third controller

UIViewController* secondController = // new controller
secondController.dataToInject = // ...
[self.navigationController pushViewController:secondController animated:YES];

其中dataToInject可以在SecondController中定义为

@property (nonatomic, retain) id dataToInject;

希望对您有所帮助。

P.S. 代码是用 Objective-C 编写的,但稍加修改也适用于 MonoTouch。例如,使用 this 而不是 self

关于ios - 在 MonoTouch 中的 View Controller 之间切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16040841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com