0

我的 FlipsideViewController 的“完成”按钮不起作用(没有崩溃,但也没有关闭视图)。这是代码:

在 FlipSideViewController.h

@class FlipsideViewController;

@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end

@interface FlipsideViewController : UIViewController

@property (weak, nonatomic) id <FlipsideViewControllerDelegate> delegate;

- (IBAction)done:(id)sender;

@end

在 FlipSideViewController.m 中

- (IBAction)done:(id)sender
{
// an NSLog statement that is here is logging properly
[self.delegate flipsideViewControllerDidFinish:self];

}

在 MainViewController.h

@interface FifthViewController : UIViewController <FlipsideViewControllerDelegate> 
...

在 MainViewController.m

- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showAlternate"]) {
    [[segue destinationViewController] setDelegate:self];
}
}

顺便说一句,这是一个选项卡式应用程序,所以我认为这可能与它有关。任何建议,将不胜感激。谢谢你。

4

2 回答 2

0

试试这个:

- (IBAction)done:(id)sender
{
   // an NSLog statement that is here is logging properly
   [self.delegate performSelector:@selector(flipsideViewControllerDidFinish:)
            withObject:self
            afterDelay:0.0];
}

有时,必须在运行循环的下一次迭代中执行解除。这就是performSelector上面的语句完成的。

于 2013-01-21T17:40:43.340 回答
0

我发现了问题。如果您查看问题代码,在 MainViewController.m 下,您必须在情节提要文件和代码中设置 segue 标识符:

if ([[segue identifier] isEqualToString:@"showAlternate"]) {
[[segue destinationViewController] setDelegate:self];
}

谢谢你,塞尔吉奥,你的帮助。

于 2013-01-23T22:14:02.383 回答