1

嗨,我是 iPhone/iPad 开发的新手。

在我的应用程序中单击按钮想要显示像 presentModalViewController 这样的视图控制器,并且我能够执行包含具有一些值的 UITableView 的操作。在选择微粒行时,我想将值传递给该控制器后面的控制器。

为此,我正在使用苹果示例应用程序 PhotoPicker 代码。http://developer.apple.com/library/ios/#samplecode/PhotoPicker/Introduction/Intro.html

但我无法理解我在代码中做错了什么。

我无法进入 MyViewController.m 中的代码

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

任何人都可以帮助我...如何从 OverlayViewController 调用此函数?

请参考上面的链接并指导我或给我一些步骤或指导我。

4

2 回答 2

0

使用委托

我在我正在写的应用程序中使用了这样的东西:

// 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
}
于 2011-02-08T11:09:14.800 回答
0

你也可以使用 NSNotificationCenter 来做到这一点。

在 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
}

来自 OverlayViewController.m:

[MyViewController callDidFinishWithCamera];

使用上面的类方法从OverlayViewController调用MyViewController中的didFinishWithCamera

于 2011-02-08T11:17:35.783 回答