Iphone ModalView

时间:2011-05-24 15:57:48

标签: iphone ios4

我有第一个控制器(itemDetailViewController):

- (void)loadView {
    CGRect frame = CGRectMake(10, 10, 300, 300);

    item1DetailView = [[Item1DetailView alloc] initWithFrame:frame andController:self];
    self.view = item1DetailView;
    [item1DetailView release];
}

// there is a button in my view : item1DetailView to call this method :
- (void)clickOnButtonToModalView:(id)sender{
    Item1DetailModalViewController *item1DetailModalViewController = [[Item1DetailModalViewController alloc] init];
    item1DetailModalViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:item1DetailModalViewController animated:YES];
    [item1DetailModalViewController release];
}

在我的第二个控制器(item1DetailModalViewController)中,我有dismissModalViewController的按钮:

- (void)clickOnButtonSortirModalView:(id)sender{
    [self dismissModalViewControllerAnimated:YES];
}

item1DetailModalViewController已关闭但item1DetailView填满了屏幕。框架是:CGRect frame = CGRectMake(10, 10, 300, 300);

我有什么遗失的吗?

我试过这个:

在我的模态视图控制器中:

@protocol Item1DetailModalViewDelegate
- (void)modalViewControllerDone;
@end
@interface Item1DetailModalViewController : UIViewController {
    Item1DetailModalView *item1DetailModalView;
    id <Item1DetailModalViewDelegate> delegate;
}
@property (nonatomic, retain) Item1DetailModalView *item1DetailModalView;
@property (nonatomic, assign) id <Item1DetailModalViewDelegate> delegate;
- (void)clickOnButtonSortirModalView:(id)sender;
@end

- (void)clickOnButtonSortirModalView:(id)sender{
    //[self dismissModalViewControllerAnimated:YES];
    [self.delegate modalViewControllerDone];
}

In my itemDetailViewController :
@interface Item1DetailViewController : UIViewController <Item1DetailModalViewDelegate>

- (void)modalViewControllerDone {
    [self dismissModalViewControllerAnimated:YES];
}

但问题已经存在......

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

dismissModalViewController必须由呈现视图1的控制器调用。在您的情况下,它是itemDetaiViewController

您需要做的是将itemDetailViewController作为委托添加到模态视图控制器。然后,当您点击按钮时,您将可以拨打:

- (void)clickOnButtonSortirModalView:(id)sender{
    [delegate modalViewControllerDone];
}

itemDetailViewController

- (void)modalViewControllerDone {
  [self dismissModalViewControllerAnimated:YES];
}