代码之家  ›  专栏  ›  技术社区  ›  ryanprayogo

Pass data between ViewControllers in a UINavigationController

  •  1
  • ryanprayogo  · 技术社区  · 14 年前

    (续) this thread )

    Suppose that I have the following view created:

    http://cl.ly/1USw/content

    “视图”按钮应该是按下一个新的“视图控制器”,它将显示乔希或艾尔的所有照片,具体取决于按下的按钮。

    我的问题是 :

    In the ViewController code, how do I determine which 'View' button is pushed (top or bottom)?

    This is the code that I have:

    - (IBAction) viewImageList {
        PhotoListViewController* photoListViewController = [[PhotoListViewController alloc] 
                                                            initWithNibName:@"PhotoListViewController" 
                                                            bundle:[NSBundle mainBundle]];
    
        // here, I want to dynamically pass in the name (Josh or Al) based on which 'View' button is pressed
        photoListViewController.ownerName = @"someName";
    
        [[self navigationController] pushViewController:photoListViewController animated:YES];
        [photoListViewController release];
    
    }
    

    Or if anyone have a different approach, I'd like to hear it :)

    2 回复  |  直到 14 年前
        1
  •  2
  •   warrenm    14 年前

    Your IBAction should receive a pointer to the sender of the event: (IBAction)viewImageList:(id)sender 你可以检查 tag 属性,或保留按钮数组,并将发件人的标识与数组中按钮的标识进行比较,以查看单击的来源。

        2
  •  1
  •   AtomRiot    14 年前

    如果这些按钮上的润色内部操作转到相同的IBaction方法调用,则可以将每个按钮的标记值设置为代码或接口生成器中唯一的值,然后判断发送者值,但添加:(id)类似发送者的

    • (IBaction)视图图像列表:(ID)发件人{ if([sender iskindofclass:[uibutton class]]).{ 乌布顿 Bunt=(uBiTon) 发送者; 开关(BTN.TAG){ …