我有一个ViewController,上面有一个UIButton。这个按钮触发一个方法,这应该在他的位置呈现一个modalVC。但由于某种原因它不再起作用了。我以前一直在使用相同的代码而没有任何问题,但它让我感到烦恼。
-(void)showModalVC //the method that's being fired by the button.
{
NSLog(@"modalVC to create a table"); //this log is being printed so the button fires as proper.
self.myModalVC = [[MyModalViewController alloc] init]; //a local var gives same results.
self.myModalVC.dismissDelegate = self; //the delegate is handled as proper.
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:self.myModalVC];
//navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:navController animated:YES];
[self.myModalVC release];
[navController release];
}
什么原因导致ModalVC不能从我们当前的视图中调用它?
我以前一直在使用这个相同的方法(在其他环境中的其他项目中)所以我感到眼花缭乱它还没有工作。该方法被触发,它会传递每行代码而不会崩溃。
如果你有想法。把它贴在这里。 感谢。
答案 0 :(得分:0)
我想到的第一件事是你在这一行创建一个泄漏的对象:
self.myModalVC = [[MyModalViewController alloc] init];
自我。将保留myModalVC,alloc也将保留它,你可能只在dealloc方法中释放它。
在所有其他方式中,代码看起来非常有效。但看看你如何使用自我。前缀,也许你的应用程序中的其他地方有内存问题?尝试阅读有关属性和访问器方法的内容。
答案 1 :(得分:0)
-(void)showModalVC
{
self.myModalVC = [[ModalVC alloc] init];
self.myModalVC.dismissDelegate = self;
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:self.myModalVC];
navController.modalPresentationStyle = UIModalPresentationFormSheet; //or something similar, this one is used on an iPad
UILabel *navTopItemTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
navTopItemTitle.text = @"Modal shizzle";
navTopItemTitle.backgroundColor = [UIColor clearColor];
navTopItemTitle.textColor = [UIColor whiteColor];
navTopItemTitle.textAlignment = UITextAlignmentCenter;
[navController.navigationBar.topItem setTitleView:navTopItemTitle];
[self presentModalViewController:navController animated:YES];
[self.addTabViewController release];
[navController release];
}
问题解决了。