当我点击我的splitviewcontroller中的popover按钮时,收到消息:发送到解除分配的实例0x6a66ca0的消息
我已经发现这个实例必须是我分配和init的detailviewcontroller。到现在为止还挺好。但是,当整个事情不起作用时,我没有看到问题。
首先我创建Splitview的AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// TestViews for SplitViewController
// TestView1 *test1 = [[TestView1 alloc] initWithNibName:@"TestView1" bundle:nil];
// TableView as RootViewController for the Left Hand Pane
RootViewTableViewController *rootViewTableViewController = [[RootViewTableViewController alloc] initWithNibName:@"RootViewTableView" bundle:nil];
UINavigationController *rootNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewTableViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:rootNavigationController,detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
return YES;
}
首先我在想代码行self.splitviewcontroller.delegate = detailviewcontroller;可能是问题.....但整个应用程序启动完美。只有当我点击按钮时才出现这个概率。
RootViewController就是这个(为了清楚起见,我省略了标准的tableview委托方法)
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Set Title of the TableView for the RootViewController
self.title = @"Notarzteinsatzprotokoll";
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
}
NSLog(@"INIT %p", self);
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
}
和详细视图控制器:
#pragma mark -
#pragma mark Managing the Detail Item
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view
[self configureView];
}
if (self.rootPopoverController != nil) {
[self.rootPopoverController dismissPopoverAnimated:YES];
}
}
- (void)configureView
{
// Update the user interface for the detail item
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setTitle:@"Notarzteinsatzprotokoll"];
[self configureView];
}
#pragma mark -
#pragma mark Rotation Support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return YES;
}
#pragma mark -
#pragma mark SplitView
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc {
barButtonItem.title = @"Master";
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
self.rootPopoverController = pc;
}
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.rootPopoverController = nil;
}
我没有看到详细视图控件对象被释放的程序流程以及其他东西尝试发送消息的重点...我是否需要交换一些代码行?
谢谢! 塞巴斯蒂安
@end
答案 0 :(得分:0)
错误应该告诉您正在发送给解除分配的实例的消息。不确定问题究竟是什么,是否将setTitle:消息发送到左栏按钮项?
在splitViewController中:willShowViewController:你将左边的条形按钮项设置为nil(它会解除它),并在splitViewController中:willHideViewController:你试图改变它的标题,这可能是你的问题。