View Controllerを介して通信するためにデリゲートを使用しようとしています。これが私のコードです:
@protocol ViewControllerDelegate;
@interface ViewController : UIViewController <UITextFieldDelegate>{
IBOutlet UIDatePicker *dateTimePicker;
}
@property (nonatomic, strong) IBOutlet UITextField *className;
@property (nonatomic, strong) IBOutlet UITextField *assignmentTitle;
@property (nonatomic, strong) IBOutlet UITextField *assignmentDescription;
@property (nonatomic, strong) IBOutlet UISwitch *procrastinationNotificationSwitch;
@property (nonatomic, strong) IBOutlet UILabel *notificationOnOffLabel;
@property (nonatomic, assign) id <ViewControllerDelegate> delegate;
@property (nonatomic,strong)classObject *classObject;
-(IBAction) addButton:(id)sender;
@end
@protocol ViewControllerDelegate <NSObject>
-(void)assignmentSaved:(classObject *)classObj;
実際に:
[self.delegate assignmentSaved:self.classObject];
他のView Controllerでは:
-(ViewController *)vc
{
if (!_vc) {
_vc = [[ViewController alloc]init];
}
return _vc;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.vc.delegate = self;
}
-(void)assignmentSaved:(classObject *)classObj
{
NSLog(@"%@",classObj.description);
classObj2 = classObj;
[self.tableView reloadData];
}
vc は のプロパティですView Controller
。デリゲートを NSLog すると、デリゲートは nil になります。また、@mialkanの回答を試しましたが、まだ機能しません。さらに情報が必要な場合は、お尋ねください。