iPhone Dev - 需要我上次访问的视图中的 id [英] iPhone Dev - need a id from the last view i visited

查看:27
本文介绍了iPhone Dev - 需要我上次访问的视图中的 id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要构建一个代码来跟踪我从订单视图中使用的 ID,但现在我无法使用它,有人可以将示例代码粘贴给我吗?

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?

我需要一个来自 view1 -> view2 的 TagID,所以当我登陆 view2 时,我可以获得关于它的信息并发送到用户屏幕.

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.

我在这里需要一点帮助:0)

i hove on a little help here :0)

推荐答案

我认为您在这里说的是您正在应用程序中从一个 UIView 移动到另一个 UIView,并且您需要某种传递"变量的方法从视图 1 到视图 2.

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.

这是 iPhone 应用设计的一个常见用例,有几种方法.这是我认为最简单的方法,它适用于任何对象(整数、NSManagedObjects 等):在第二个视图中创建一个 iVar 并将其设置为要跟踪的值,然后再使其可见.

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.

在您的 ViewTwoController 中使用以下内容进行设置:

Set this up in your ViewTwoController with something like:

ViewTwoController.h:
====================
@interface ViewTwoController : UIViewController {
    NSUInteger *tagID;
}
@property (nonatomic, assign) NSUInteger *tagID;
@end

ViewTwoController.m
===================
@synthesize tagID;

所以此时您的 ViewTwoController 有一个用于 tagID 的 iVar.现在我们在 View One 中要做的就是创建 ViewTwoController,为 tagID 赋值,然后显示第二个视图.这可以在您的按钮按下选择器中完成,也可以从 UITableView 行中完成:

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:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ViewTwoController *viewTwoController = [[ViewTwoController alloc] init];
    viewTwoController.tagID = self.tagID;  // !! Here is where you "pass" the value
    [self.navigationController pushViewController:viewTwoController animated:YES];
}

上面代码的作用是:(1)创建一个新的ViewTwoController,(2)将tagID的值赋给ViewTwoController中的tagID iVar,然后(3)将视图二呈现给用户.因此,在您的 ViewTwoController 代码中,您可以使用 self.tagID 访问 tagID.

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.

希望这会有所帮助!

这篇关于iPhone Dev - 需要我上次访问的视图中的 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆