在导航控制器中有两个视图控制器:
PhoneNumbersTVC
> 保存由NewPhoneNumberTVC
NewPhoneNumberTVC
> 添加电话号码的控制器添加的电话号码列表
当我点击取消时,NewPhoneNumberTVC
我想回到PhoneNumbersTVC
一个代表团,如下所示。
电话号码TVC.h
#import <UIKit/UIKit.h>
#import "NewPhoneNumberTVC.h"
@interface PhoneNumbersTVC : UITableViewController <NewPhoneNumberTVCDelegate>
@end
电话号码TVC.m
- (void)saveBtnWasTappedOnNewPhoneNumberTVC:(NewPhoneNumberTVC *)newPhoneNumberTVC
{
NSLog(@"saveBtnWasTappedOnNewPhoneNumberTVC");
[newPhoneNumberTVC.navigationController popViewControllerAnimated:YES];
}
- (void)cancelBtnWasTappedOnNewPhoneNumberTVC:(NewPhoneNumberTVC *)newPhoneNumberTVC
{
NSLog(@"cancelBtnWasTappedOnNewPhoneNumberTVC");
[newPhoneNumberTVC.navigationController popViewControllerAnimated:YES];
}
新电话号码TVC.h
#import <UIKit/UIKit.h>
@class NewPhoneNumberTVC;
@protocol NewPhoneNumberTVCDelegate <NSObject>
- (void)saveBtnWasTappedOnNewPhoneNumberTVC:(NewPhoneNumberTVC *)newPhoneNumberTVC;
- (void)cancelBtnWasTappedOnNewPhoneNumberTVC:(NewPhoneNumberTVC *)newPhoneNumberTVC;
@end
@interface NewPhoneNumberTVC : UITableViewController
@property (weak, nonatomic) id <NewPhoneNumberTVCDelegate> delegate;
@property (strong, nonatomic) NSManagedObjectContext *managedOC;
@property (weak, nonatomic) IBOutlet UITextField *phoneNumberTextField;
- (IBAction)saveBtnTapped:(UIBarButtonItem *)sender;
- (IBAction)cancelBtnTapped:(UIBarButtonItem *)sender;
@end
新电话号码TVC.m
- (IBAction)cancelBtnTapped:(UIBarButtonItem *)sender
{
NSLog(@"cancelBtnTapped");
self.phoneNumberTextField.text = @"";
self.phoneKindTextField.text = @"";
[self.delegate cancelBtnWasTappedOnNewPhoneNumberTVC:self];
}
当我点击取消时,NewPhoneNumberTVC
我看到上面的方法cancelBtnTapped
触发但delegation
不起作用,没有method
执行PhoneNumbersTVC
。视图没有消失,我没有看到:cancelBtnWasTappedOnNewPhoneNumberTVC
on console
。