我想重用代碼,我有一些教程視圖控制器/視圖,我想從操作表調用。但是,調用視圖是不同的。有時,教程視圖將需要添加爲子視圖,有時它們將被添加到導航控制器。在具有參數的標準方法中使用addSubView或presentModalViewController?
如何擴展我的標準功能以迎合這兩種不同情況?
你可以看到我在做相反,這意味着重複的代碼:(
我有一個叫做類擁有標準的代碼,我想在這裏呼籲直接添加到的意見是什麼。
-(void)showHelpClickButtonAtIndex:(int)buttonIndex:(UIView *)vw {
if (buttonIndex == CommonUIHelpPagesBtnIdx) {
// do nothing
} else if (buttonIndex == 0) {
NSLog(@"Tutorial here");
}
}
我在這樣一個視圖中使用...
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex {
CommonUI *cui = [CommonUI alloc];
[cui showHelpClickButtonAtIndex:buttonIndex:self.view];
[cui release];
if (buttonIndex == CommonUIHelpPagesBtnIdx) {
UIViewController *theController = [[HelpViewController alloc]
initWithNibName:@"HelpView"
bundle:nil onPage:HelpPageCalcBalance];
[self.navigationController.topViewController
presentModalViewController:theController animated:YES];
[theController release];
}
}
,是這樣的另一種觀點認爲...
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex {
[cui showHelpClickButtonAtIndex:buttonIndex:self.view];
if (buttonIndex == CommonUIHelpPagesBtnIdx) {
theController = [[HelpViewController alloc] initWithNibName:@"HelpView"
bundle:nil onPage:HelpPageGettingStarted];
[self.view addSubview:theController.view];
}
}
從你的代碼,我相信調用viewController發送自己作爲委託的參數,也許如果你不嘗試這樣做,並總是使用像你的appDelegate相同的代表,這可能會有所幫助。 – ebany 2010-11-16 12:50:55
如果這與tabBar問題相同,如果您將ApplicationDelegate設置爲UIActionSheetDelegate,並將其設置爲委託([[UIApplication sharedApplication]委託]),則它可以響應您的actionSheets方法並知道該怎麼做。既可以在窗口中顯示視圖,也可以將(從模態到或不從)導航控制器的topViewController中的視圖從TabBarController的選定選項卡中檢索。 – ebany 2010-11-16 13:04:34
剛剛編輯我的答案,讓我知道如果這有助於 – ebany 2010-11-16 13:45:07