开发者

How can I make different buttons show different data on a single screen on iPad

开发者 https://www.devze.com 2023-04-07 17:05 出处:网络
I am making an app for iPad with different views. Till now I have added 2 views. First view is the home screen which has a single button and some images. Pressing button on first view navigates to the

I am making an app for iPad with different views. Till now I have added 2 views. First view is the home screen which has a single button and some images. Pressing button on first view navigates to the second view. Second view has 6 buttons. Now what I want to do is when I press any button on second view, it navigates to the third view. Each button on second view has to show different data. I don't want 6 different views, instead I want a single third view but it should show only that particular data respective to the button pressed on second view. How can i开发者_JAVA百科t be done?? Please help me with the code.. Any help will be highly appreciated..


You just need a variable in the third view that you set before showing it. I would set a different tag value for each of my buttons and have them all call a single method. In that method, check the tag value of the sender and setup the third view accordingly. Then show it.

In the third view's viewDidLoad method you can handle displaying or setting up the new data you assigned to it.

For example, if you were setting some custom text in the third view you would have this for your button method in the second view:

- (IBAction)buttonTap:(id)sender {
   UIButton *tappedButton = (UIButton *)sender;

   MyThirdViewController *thirdVC = [[MyThirdViewController alloc] initWithNib:@"MyThirdViewController" bundle:nil];
   switch (tappedButton.tag) {
       case 1:
           thirdVC.customText = @"Something for button 1";
           break;
       case 2:
           thirdVC.customText = @"Something for button 2";
           break;
       case 3:
           thirdVC.customText = @"Something for button 3";
           break;

   }
   [self.navigationController pushViewController: thirdVC];
   [thirdVC release];

}

In the third ViewController:

- (void)viewDidLoad {
    self.myTextView.text = self.customText;
}
0

精彩评论

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