如何在iPhone/iPad中使用presentModalViewController?

发布于 2024-10-16 03:55:49 字数 687 浏览 1 评论 0原文

大家好,我是 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 调用此函数?

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

dawn曙光 2024-10-23 03:55:49

使用委托

我在我目前正在编写的应用程序中使用类似的东西:

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

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
}
若水般的淡然安静女子 2024-10-23 03:55:49

您还可以使用 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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文