我想重用代码,我有一些教程视图控制器/视图,我想从操作表调用。但是,调用视图是不同的。有时,教程视图将需要添加为子视图,有时它们将被添加到导航控制器。在具有参数的标准方法中使用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