开发者

Pass data between ViewControllers in a UINavigationController

开发者 https://www.devze.com 2023-01-04 18:29 出处:网络
(Continued from this thread) Suppose that I have the following view created: http://cl.ly/1USw/content The \'View\' button is supposed to push a new ViewController which will show all photos by eit

(Continued from this thread)

Suppose that I have the following view created:

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

The 'View' button is supposed to push a new ViewController which will show all photos by either Josh or Al, depending on which button is pressed.

My question is:

In the ViewController code, how do开发者_C百科 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 :)


Your IBAction should receive a pointer to the sender of the event: (IBAction)viewImageList:(id)sender You can either inspect the tag property of the sender, or keep an array of the buttons and compare the identity of the sender to the identities of the buttons in the array to see where the click originated.


If your touch up inside action on those buttons go to the same ibaction method call, you can set the tag value of each button to something unique in code or interface builder then judge the senders value but adding :(id)sender like

  • (IBAction) viewImageList:(id)sender{ if([sender isKindOfClass:[UIButton class]]){ uIButton btn =(UIButton)sender; switch(btn.tag){ ...
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号