简体   繁体   中英

How to use presentModalViewController in iPhone/iPad?

Hi i am very new in iPhone/iPad developmet.

In my application on clicking of button in want to show view controller like presentModalViewController and i am able to do that which contains the UITableView with some numbers of values. on selecting particulate row i want to pass values to controller which is behind that controller.

for that i am using apple sample application PhotoPicker code. http://developer.apple.com/library/ios/#samplecode/PhotoPicker/Introduction/Intro.html

But i am not able to understand the what i did wrong in my code.

I am not able to go in the code which is in the MyViewController.m

- (void)didFinishWithCamera
{
    [self dismissModalViewControllerAnimated:YES];
//Here is my some logic
}

can any one help me for this...how to call this function from OverlayViewController?

please refer above link and guide me or give me some steps or guide me for the same.

use delegation .

I use something like this in a app I'm writing at the moment:

// MySecretSelectionViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [delegate mySecretSelectionViewController:self didSelectObject:[self objectForIndexPath:indexPath] atIndexPath:indexPath];
}

// MyViewController.m
- (void)mySecretSelectionViewController:(MySecretSelectionViewController *)es didSelectObject:(MySecretObject *)object atIndexPath:(NSIndexPath *)indexPath {
    // do something with the selected object
    [self dismissModalViewControllerAnimated:YES];
}

- (void)showMySecretSelectionViewController:(id)sender {
    MySecretSelectionViewController *vc = ...
    vc.delegate = self;
    // present ViewController
}

You can also do this with use of NSNotificationCenter.

Inside MyViewController.m:

- (void)viewDidLoad 
{
    // your code

    // Add observers
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishWithCamera) name:@"YourObserverName" object:nil];
}

+ (void)callDidFinishWithCamera
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"YourObserverName" object:nil];
}

- (void)dealloc 
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];

    // your code
}

From OverlayViewController.m:

[MyViewController callDidFinishWithCamera];

Use the above class method to call didFinishWithCamera in MyViewController from OverlayViewController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM