我使用這兩種協議是這樣的:呼叫多個視圖控制器的UITableView
@protocol ModalClosedProtocol <NSObject>
-(void) modalClosedGlobalProtocolMethod;
@end
和syncmlClient協議。
有三類ContactsViewController
,EventViewController
,ImageSettingViewController
。這些類使用ModalclosedProtocol
和syncmlClient protocol.all這三類預計從SettingViewController
類來實現ModalClosedProtocol
和syncmlClient protocol.It是當前實現的只是一個簡短的概述。
在我SettingViewController
我正在處理表委託方法didSelectRow
。對於代碼保理我創建了從0稱爲一個獨立的方法..像這樣:
-(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
}
}
基本上,如果你看到有很多redudancy的代碼在if/else
子句中。如果我有一個單一的UIViewController
對象,從代碼管理的角度來看會更好。
genericVC = contactVc;//vc object passed from didSelectrow it may be contact/event/image
genericVC.modalClosedProtocolDelegate = self;
genericVC.syncmlClient = self.syncmlClient;
genericVC.mainViewController = self.mainViewController;
有人可以幫我解決這個問題。
感謝
親愛的讓我檢查現在.. :)謝謝 – Alok
你是正確的,但是通過的參數也應該宣佈相同,如你所建議的,否則你會得到不兼容的viewcontrooler錯誤 – Alok
我只需要改變方法定義像這樣:-(void)checkDeviceAndHandleModelSizeForFlip: (FlipsideViewController *)flipVc orContact: –
Alok