gpt4 book ai didi

iphone - splitview 委托(delegate)方法没有被调用

转载 作者:行者123 更新时间:2023-12-03 21:16:41 26 4
gpt4 key购买 nike

大家好,我在我的 iPad 应用程序中使用 splitviewcontroller,其中选择 TableView 中的每一行将显示新的详细 View Controller ,在我的一个详细 View 中,我再次推送一个新的详细 View Controller (detailview2),并在该类(detailview2)中我定义一个协议(protocol)并设置它,当按下后退按钮时,协议(protocol)方法被触发,我的 rootview (tableview)正在实现该协议(protocol),但即使在设置委托(delegate)之后,方法也不会被调用。如果我在detailview1和rootview中定义相同的协议(protocol)实现然后协议(protocol)方法不会被调用,下面我发布了代码。我不明白为什么会这样。任何建议都会有很大的帮助。 Detailview2.h

  @protocol ModalControllerDelegate;
@interface ViewController : UIViewController<UIPopoverControllerDelegate, UISplitViewControllerDelegate>{
}
@property (nonatomic, assign) id <ModalControllerDelegate> delegate;
@end
@protocol ModalControllerDelegate <NSObject>
- (void)modalControllerDidFinish:(ViewController*)modalController;
@end

Detailview2.m

-(void)back {
// Tell the controller to go back
NSLog(@"ghhskfh");
[delegate modalControllerDidFinish:self];
[self.navigationController popViewControllerAnimated:YES];
}

Root View .h

@interface RootViewController : UITableViewController<UITableViewDelegate, UITableViewDataSource,ModalDelegate,ModalControllerDelegate> {
FirstDetailViewController *firstDetailViewController;
SecondDetailViewController *secondDetailViewController;
MultipleDetailViewsWithNavigatorAppDelegate *appDelegate;
}
@end

Root View .m

- (void)viewDidLoad 
{
[super viewDidLoad];
self.title=@"RootView";
self.viewcontroller=[[ViewController alloc]init];
self.viewcontroller.delegate=self;
//[self.tableView setDelegate:self];
//[self.tableView setDataSource:self];
}
#pragma mark -
#pragma mark ModalController delegate
- (void)modalControllerDidFinish:(ViewController *)modalController {
NSLog(@"modalControllerDidFinish");
}

myappdelegate.m(如果需要)

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
// Override point for customization after app launch.
self.splitViewController =[[UISplitViewController alloc]init];
self.rootViewController=[[RootViewController alloc]init];
self.detailViewController=[[[FirstDetailViewController alloc]init] autorelease];
UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];
self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
self.splitViewController.delegate=self.detailViewController;
// Add the split view controller's view to the window and display.
[window addSubview:self.splitViewController.view];
[window makeKeyAndVisible];
return YES;
}

最佳答案

在您的应用程序委托(delegate)方法中实现以下代码可能会解决您的问题。

请尝试下面的代码,我认为它可以用于调用代表。

已编辑

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
// Override point for customization after app launch.
self.splitViewController =[[UISplitViewController alloc]init];
self.rootViewController=[[RootViewController alloc]init];
self.detailViewController=[[[FirstDetailViewController alloc]init] autorelease];
UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];
self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
self.splitViewController.delegate=self.detailViewController;
//Changes Made here
self.rootViewController.firstDetailViewController=self.detailViewController;
// Add the split view controller's view to the window and display.
[window addSubview:self.splitViewController.view];
[window makeKeyAndVisible];
return YES;
}

关于iphone - splitview 委托(delegate)方法没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11947083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com