Вопрос

i am using two protocol something like this:

@protocol ModalClosedProtocol <NSObject>

-(void) modalClosedGlobalProtocolMethod;

@end

and syncmlClient Protocol.

There are three classes ContactsViewController, EventViewController, ImageSettingViewController.These classes use ModalclosedProtocol and syncmlClient protocol.all these three classes expects from SettingViewController class to implement ModalClosedProtocol and syncmlClient protocol.It is just a short overview of current implementation.
In my SettingViewController i am handling table delegate method didSelectRow.for code factoring i have created a separate method which is called from didSelectRow.. like this:

    -(void) checkDeviceAndHandleModelSizeForFlip:(FlipsideViewController *)flipVc orContact:(ContactsViewController *)contactVc orEvent:(EventViewController *)eventVc orImage:(ImageSettingViewController *)imageSettingVc
{  
    UIViewController *genericVC;  
    if (flipVc!=nil)  
    {  
        genericVC = flipVc;  
        flipVc.modalClosedProtocolDelegate = self;  
        flipVc.syncmlClient = self.syncmlClient; 

    }  
    else if (contactVc!=nil)  
    {
        genericVC = contactVc;  
        contactVc.modalClosedProtocolDelegate = self;  
        contactVc.syncmlClient = self.syncmlClient;  
        contactVc.mainViewController = self.mainViewController;  
    }  
    else if (eventVc!=nil)  
    {  
        genericVC = eventVc;  
        eventVc.modalClosedProtocolDelegate = self;  
        eventVc.syncmlClient = self.syncmlClient;  
        eventVc.mainViewController = self.mainViewController;  
    }  
    else if (imageSettingVc!=nil)  
    {
        genericVC = imageSettingVc;
        imageSettingVc.modalClosedProtocolDelegate = self;
        imageSettingVc.syncmlClient = self.syncmlClient;
        imageSettingVc.mainViewController = self.mainViewController;

    }

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
    {
        genericVC.modalPresentationStyle = UIModalPresentationFormSheet;
        [self presentViewController:genericVC  animated:YES completion:nil];
        genericVC.view.superview.frame = CGRectInset(genericVC.view.superview.frame, 100, 50);
    }
    else
    {
        genericVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self presentViewController:genericVC  animated:YES completion:nil]; //alok

    }
}

basically if you see there is lot of redudancy in code in if/else clause.It would be better from code management point of view if i had a single UIViewController object.

genericVC = contactVc;//vc object passed from didSelectrow it may be contact/event/image  
    genericVC.modalClosedProtocolDelegate = self;  
    genericVC.syncmlClient = self.syncmlClient;  
    genericVC.mainViewController = self.mainViewController;

can some one help me regarding this problem.
Thanks

Это было полезно?

Решение

Just declare your genericVC like this:

UIViewController<ModalClosedProtocol, syncmlClient> *genericVC;

This way you let the compiler know that your genericVC View Controller conforms to the protocols ModalClosedProtocol and syncmlClient, so the methods you want to call are there.

Другие советы

[self checkDeviceAndHandleModelSizeForFlip:self.flipVc];//Pass contactVc, eventVc, imageSettingVc like that,

-(void) checkDeviceAndHandleModelSizeForFlip:(ViewController *)viewController
{
    UIViewController *genericVC;
    if (viewController!=nil)
    {
        genericVC = viewController;
        viewController.modalClosedProtocolDelegate = self;
        viewController.syncmlClient = self.syncmlClient;
        viewController.mainViewController = self.mainViewController;

    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top