0

我对 iOS SDK 很陌生,但我一直在尝试使用 UITableViewController 作为另一个 VC 的委托。问题是一个更大的应用程序的一部分,但我在下面对其进行了简化,一旦在第二个 VC 上按下“完成”,我尝试让 UITableViewController 关闭第二个 VC。

MainViewController.h (UITableViewController)

    #import <UIKit/UIKit.h>
    #import "SecondViewController.h"

    @interface MainViewController : UITableViewController <SecondViewControllerDelegate>
    @end

主视图控制器.m

- (void)doneEditing {
    [self dismissViewControllerAnimated:YES completion:nil];
}

SecondViewController.h

#import <UIKit/UIKit.h>

@class SecondViewController;
@protocol SecondViewControllerDelegate <NSObject>
- (void)doneEditing;
@end

@interface SecondViewController : UIViewController

@property (weak, nonatomic) id <SecondViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
@end 

第二视图控制器.m

- (IBAction)done:(id)sender {
    [self.delegate doneEditing];
}

如果 Main 不是 UITableViewController,它可以工作。我注意到触摸时会识别“完成”,但从未调用过“doneEditing”方法。

4

1 回答 1

0

如果您使用情节提要,则应使用展开转场。UIViewController这是一种无需授权即可解除模式的简单方法。这是一个很好的关于 unwind segues 的教程

于 2013-08-27T04:40:41.000 回答