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

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 に答える
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 に答える