يتم استدعاء أسلوب المندوب من فئة واحدة، ولكن ليس من فئة أخرى ذات بنية مماثلة

StackOverflow https://stackoverflow.com//questions/24000136

سؤال

لدي ثلاثة فصول. 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

تفاصيل الاستخدام الطرق ذات الصلة بـVC.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];
}

التنبيهات:

تفاصيل التنبيهVC.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:

حددIOVC.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 بين UtilizationDetailsVCScene و ال SelectIOVC Scene.

ضبط القيمة على بلدي وفقا Identifier التي كنت أتحقق منها لإصلاح مشكلتي.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top