대리자의 메서드가 한 클래스에서 호출되지만 동일한 구조를 가진 다른 클래스에서는 호출되지 않습니다.
-
20-12-2019 - |
문제
수업이 세 개 있어요. AlertDetailsVC
, UtilizationDetailsVC
그리고 SelectIOVC
.
UtilizationDetailsVC
본질적으로 다음의 사본입니다. AlertDetailsVC
약간의 수정으로.
사용자가 Scene
나를 위해 AlertDetailsVC
그는 버튼을 한 번에 누를 수 있어요 Table
~라고 불리는 Applies To
.그 사람이 이걸 누르면 Applies To
버튼을 누르면 프로그램이 Segues
새로운 Scene
사용하는 SelectIOVC
;그런 다음 Delegate
그 장면의 Delegate
에 정의되어 있습니다. AlertDetailsVC
.
그런 다음 사용자가 Done
에 Navigation Bar
에 SelectIOIOVC
Scene
;그만큼 SelectIOVC
그런 다음 클래스는 사용자가 선택한 일부 데이터와 정보를 다시 반환합니다. AlertDetailsVC
.
이 흐름은 유사하게 복사됩니다. UtilizationDetailsVC
.
여러개 추가했어요 NSLog(@"%s",__PRETTY_FUNCTION__);
호출되어야 하는 내 메서드의 줄입니다.
지금;내가 쳤을 때 Done
내 AlertDetailsVC
메소드가 올바르게 호출되고 프로그램이 Segues
에서 돌아오다 SelectIOVC
나에게 AlertDetailsVC
사용자가 입력한 해당 페이지의 정보를 업데이트합니다.
그러나 내 문제는 다음과 같습니다.내가 내 안에서 똑같은 일을 할 때 UtilizationDetailsVC
페이지;그리고 그것을 누르세요' Done
단추;프로그램은 그렇지 않습니다 Segue
뒤쪽에.
잘 모르겠습니다.내 기록에 따르면 첫 번째 SelectIOVCDidSave
다음의 경우에 호출됩니다. AlertDetailsVC
;하지만 그것은 결코 호출되지 않습니다 UtilizationDetailsVC
.
관련 코드:
이용:
`UtilizationDetailsVC.h`:
@class UtilizationDetailVC;
@protocol UtilizationDetailsVCDelegate <NSObject>
- (void)utilizationDetailsVCDidCancel: (UtilizationDetailVC *)controller;
- (void)utilizationDetailsVCDidDelete: (UtilizationDetailVC *)controller;
- (void)utilizationDetailsVCDidSave: (UtilizationDetailVC *)controller;
@end
@interface UtilizationDetailVC : UITableViewController <UITextFieldDelegate, UIActionSheetDelegate, SelectTimeVCDelegate, SelectDaysVCDelegate, SelectIOVCDelegate, SelectIODetailsVCDelegate, SelectTimeLengthVCDelegate, MessageVCDelegate, UtilizationContactsVCDelegate, SelectDateVCDelegate>
@property (weak, nonatomic) IBOutlet UIBarButtonItem *doneButton;
@property (strong, nonatomic) NCUtilization *utilization;
@property (weak, nonatomic) id <UtilizationDetailsVCDelegate> delegate;
@property (strong, nonatomic) NSString *identifier;
@property (strong, nonatomic) NSIndexPath *indexPath;
@property (strong, nonatomic) IBOutlet UITableViewCell *cellEnabled;
@property (strong, nonatomic) IBOutlet UITextField *titleField;
@property (strong, nonatomic) IBOutlet UITextField *descriptionField;
@property (strong, nonatomic) IBOutlet UILabel *startTimeField;
@property (strong, nonatomic) IBOutlet UILabel *endTimeField;
@property (strong, nonatomic) IBOutlet UISwitch *allDayField;
@property (strong, nonatomic) IBOutlet UILabel *daysField;
@property (strong, nonatomic) NSArray *days;
@property (strong, nonatomic) IBOutlet UILabel *appliesToField;
@property (strong, nonatomic) IBOutlet UILabel *notifyWhenField;
@property (strong, nonatomic) IBOutlet UILabel *changeExistsForField;
@property (strong, nonatomic) IBOutlet UILabel *contactsField;
@property (strong, nonatomic) NSArray *contactUUIDs;
@property (strong, nonatomic) IBOutlet UILabel *messageField;
@property (strong, nonatomic) IBOutlet UILabel *startDateField;
@property (strong, nonatomic) NSDate *startDate;
@property (strong, nonatomic) IBOutlet UILabel *endDateField;
@property (strong, nonatomic) NSDate *endDate;
- (IBAction)cancel:(id)sender;
- (IBAction)done:(id)sender;
@end
UtilizationDetailsVC.m 관련 메소드:
- (void)selectIOVCDidCancel:(SelectIOVC *)controller
{
NSLog(@"%s",__PRETTY_FUNCTION__);
[self.navigationController popViewControllerAnimated:YES];
}
- (void)selectIOVCDidSave:(SelectIOVC *)controller
{
NSLog(@"%s",__PRETTY_FUNCTION__);
// Update input/output information with user selection on UI.
self.appliesToField.text = controller.ioDescription;
self.notifyWhenField.text = @"";
[self.navigationController popViewControllerAnimated:YES];
}
경고:
AlertDetailsVC.h:
#import <UIKit/UIKit.h>
#import "NCAlert.h"
#import "SelectTimeVC.h"
#import "SelectDaysVC.h"
#import "SelectIOVC.h"
#import "SelectIODetailsVC.h"
#import "SelectTimeLengthVC.h"
#import "MessageVC.h"
#import "AlertContactsVC.h"
@class AlertDetailsVC;
@protocol AlertDetailsVCDelegate <NSObject>
- (void)alertDetailsVCDidCancel: (AlertDetailsVC *)controller;
- (void)alertDetailsVCDidDelete: (AlertDetailsVC *)controller;
- (void)alertDetailsVCDidSave: (AlertDetailsVC *)controller;
@end
@interface AlertDetailsVC : UITableViewController <UITextFieldDelegate, UIActionSheetDelegate, SelectTimeVCDelegate, SelectDaysVCDelegate, SelectIOVCDelegate, SelectIODetailsVCDelegate, SelectTimeLengthVCDelegate, MessageVCDelegate, AlertContactsVCDelegate>
@property (weak, nonatomic) IBOutlet UIBarButtonItem *doneButton;
@property (strong, nonatomic) NCAlert *alert;
@property (weak, nonatomic) id <AlertDetailsVCDelegate> delegate;
@property (strong, nonatomic) NSString *identifier;
@property (strong, nonatomic) NSIndexPath *indexPath;
@property (strong, nonatomic) IBOutlet UITableViewCell *cellEnabled;
@property (strong, nonatomic) IBOutlet UITextField *titleField;
@property (strong, nonatomic) IBOutlet UITextField *descriptionField;
@property (strong, nonatomic) IBOutlet UILabel *startTimeField;
@property (strong, nonatomic) IBOutlet UILabel *endTimeField;
@property (strong, nonatomic) IBOutlet UISwitch *allDayField;
@property (strong, nonatomic) IBOutlet UILabel *daysField;
@property (strong, nonatomic) NSArray *days;
@property (strong, nonatomic) IBOutlet UILabel *appliesToField;
@property (strong, nonatomic) IBOutlet UILabel *notifyWhenField;
@property (strong, nonatomic) IBOutlet UILabel *changeExistsForField;
@property (strong, nonatomic) IBOutlet UISwitch *localAlertField;
@property (strong, nonatomic) IBOutlet UISwitch *localAlertAudioField;
@property (strong, nonatomic) IBOutlet UILabel *contactsField;
@property (strong, nonatomic) NSArray *contactUUIDs;
@property (strong, nonatomic) IBOutlet UILabel *messageField;
- (IBAction)cancel:(id)sender;
- (IBAction)done:(id)sender;
@end
AlertDetailsVC.m 관련 메소드:
- (void)selectIOVCDidCancel:(SelectIOVC *)controller
{
NSLog(@"%s",__PRETTY_FUNCTION__);
[self.navigationController popViewControllerAnimated:YES];
}
- (void)selectIOVCDidSave:(SelectIOVC *)controller
{
NSLog(@"%s",__PRETTY_FUNCTION__);
// Update input/output information with user selection on UI.
self.appliesToField.text = controller.ioDescription;
self.notifyWhenField.text = @"";
[self.navigationController popViewControllerAnimated:YES];
}
선택IOVC:
SelectIOVC.h
#import <UIKit/UIKit.h>
@class SelectIOVC;
@protocol SelectIOVCDelegate <NSObject>
- (void)selectIOVCDidCancel: (SelectIOVC *)controller;
- (void)selectIOVCDidSave: (SelectIOVC *)controller;
@end
@interface SelectIOVC : UITableViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
NSArray *selectIOType;
NSArray *selectIO;
}
@property (weak, nonatomic) IBOutlet UIBarButtonItem *doneButton;
@property (weak, nonatomic) id <SelectIOVCDelegate> delegate;
@property (weak, nonatomic) NSString *identifier;
@property (strong, nonatomic) IBOutlet UIPickerView *picker;
@property (assign, nonatomic) NSUInteger type;
@property (assign, nonatomic) NSUInteger io;
@property (assign, nonatomic) NSUInteger number;
@property (strong, nonatomic) NSString *ioDescription;
- (IBAction)cancel:(id)sender;
- (IBAction)done:(id)sender;
@end
SelectIOVC.m 관련 방법:
- (IBAction)cancel:(id)sender
{
[self.delegate selectIOVCDidCancel:self];
NSLog(@"%s",__PRETTY_FUNCTION__);
}
- (IBAction)done:(id)sender
{
NSLog(@"%s",__PRETTY_FUNCTION__);
NSString *typeDescription = [selectIOType objectAtIndex:self.type];
NSString *ioDescription = [selectIO objectAtIndex:self.io];
self.ioDescription = [NSString stringWithFormat:@"%@ %@ %01d", typeDescription, ioDescription, self.number];
[self.delegate selectIOVCDidSave:self];
}
- (void)viewDidUnload {
[self setDoneButton:nil];
[super viewDidUnload];
}
해결책
나는 이 문제를 해결했습니다.나는 - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
둘 다 내 UtilizationDetailsVC
뿐만 아니라 내 AlertDetailsVC
.
하지만;내 실수는 내가 Segue Identifier
위해 Segue
~ 사이 UtilizationDetailsVC
'에스 Scene
그리고 SelectIOVC
Scene
.
내 값에 따라 값을 설정 Identifier
내 문제가 해결되었는지 확인하고 있었거든요.