iPhone Dev - 需要我上次访问的视图的 ID
我需要构建一个代码来跟踪我从订单视图中使用的 id,但现在我无法让它工作,有人可以将示例代码粘贴给我吗?
我需要 view1 中的 TagID -> view2,所以当我登陆 view2 时,我可以获取有关它的信息并将其发送到用户屏幕。
我在这里寻求一点帮助:0)
I need to build a code to track what id i use from an order view, but now i can't get it to work, can somebody paste a sample code to me?
i need a TagID from view1 -> view2, so when i'm landing on view2 i can get informations about it and send to users screen.
i hove on a little help here :0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你在这里所说的是,你正在应用程序中从一个 UIView 移动到另一个 UIView,并且你需要某种方法将变量从 view1“传递”到 view2。
这是 iPhone 应用程序设计的常见用例,有几种方法。这是我认为最简单的方法,它适用于任何对象(整数、NSManagedObjects 等):在第二个视图中创建一个 iVar 并在使其可见之前将其设置为您想要跟踪的值。
在您的 ViewTwoController 中进行如下设置:
因此,此时您的 ViewTwoController 有一个用于 tagID 的 iVar。现在,我们在视图一中要做的就是创建 ViewTwoController,为 tagID 分配一个值,然后显示第二个视图。这可以在按钮按下选择器中完成,或者从 UITableView 行中完成,如下所示:
上面的代码的作用是:(1) 创建一个新的 ViewTwoController,(2) 将 tagID 的值分配给 ViewTwoController 中的 tagID iVar,然后(3)向用户呈现视图二。因此,在 ViewTwoController 代码中,您可以使用
self.tagID
访问 tagID。希望这有帮助!
I think what you're saying here is that you are moving from one UIView to another in your application, and you need some way of "passing" a variable from view1 to view2.
This is a common use-case with iPhone app design, and there are a few approaches. Here is what I think is the easiest approach, and it will work for any object at all (integers, NSManagedObjects, whatever): create an iVar in your second view and set it to the value you want to track before you make it visible.
Set this up in your ViewTwoController with something like:
So at this point your ViewTwoController has an iVar for tagID. Now all we have to do from View One is create the ViewTwoController, assign a value to tagID, then display that second view. This could be done in your button press selector, or from a UITableView row as such:
What the code above does is: (1) create a new ViewTwoController, (2) assign the value of the tagID to the tagID iVar in ViewTwoController, then (3) present view two to the user. So in your ViewTwoController code, you can access the tagID with
self.tagID
.Hope this helps!