Unbalanced calls to begin/end appearance transitions for <UIViewController>

http://stackoverflow.com/questions/22676938/unbalanced-calls-to-begin-end-appearance-transitions-for-uiviewcontroller

Based on the Apple documentation I came up with the following method to switch between controllers in a containment controller. When there is an oldC I am getting Unbalanced calls to begin/end appearance transitions for <...> on the console.

- (void) showController:(UIViewController*)newC withView:(UIView*)contentView animated:(BOOL)animated
{
    UIViewController *oldC = self.childViewControllers.firstObject;
    if (oldC == newC) {
        return;
    }

    [oldC willMoveToParentViewController:nil];

    [self addChildViewController:newC];
    newC.view.frame = (CGRect){ 0, 0, contentView.frame.size };
    [contentView addSubview:newC.view];

    if (animated && oldC != nil) {
        oldC.view.alpha = 1.0f;
        newC.view.alpha = 0.0f;
        [self transitionFromViewController:oldC toViewController:newC duration:0.25f options:0 animations:^{

            oldC.view.alpha = 0.0f;
            newC.view.alpha = 1.0f;

         } completion:^(BOOL finished) {
            [oldC removeFromParentViewController];
            [newC didMoveToParentViewController:self];
         }];
    } else {
        oldC.view.alpha = 0.0f;
        newC.view.alpha = 1.0f;
        [oldC removeFromParentViewController];
        [newC didMoveToParentViewController:self];
    }
}

This is how I call it:

- (IBAction) buttonSignIn:(id)sender
{
    [self showController:self.signInViewController withView:self.contentView animated:(sender != nil)];
}

- (IBAction) buttonSignUp:(id)sender
{
    [self showController:self.signUpViewController withView:self.contentView animated:(sender != nil)];
}

To track this down I am logging the appearance transitions

-(void)beginAppearanceTransition:(BOOL)isAppearing animated:(BOOL)animated
{
    [super beginAppearanceTransition:isAppearing animated:animated];
    NSLog(@"**begin %@", self);
}

-(void)endAppearanceTransition
{
    [super endAppearanceTransition];
    NSLog(@"**end** %@", self);
}

This is what the log looks like:

] **begin <SignInViewController: 0x10c769a20>
] **begin <SignUpViewController: 0x10c768770>
] Unbalanced calls to begin/end appearance transitions for <SignUpViewController: 0x10c768770>.
] **end** <SignUpViewController: 0x10c768770>
] **end** <SignInViewController: 0x10c769a20>

Now I am a little puzzled. What's the problem here?

问题解决办法:

Turns out transitionFromViewController:toViewController:duration:options:animations:completion: also adds the view.

This method adds the second view controller’s view to the view hierarchy and then performs the animations defined in your animations block. After the animation completes, it removes the first view controller’s view from the view hierarchy.

Which means the addSubview needs to be adjusted accordingly.

- (void) showController:(UIViewController*)newC withView:(UIView*)contentView animated:(BOOL)animated
{
    UIViewController *oldC = self.childViewControllers.firstObject;
    if (oldC == newC) {
        return;
    }

    [oldC willMoveToParentViewController:nil];

    [self addChildViewController:newC];
    newC.view.frame = (CGRect){ 0, 0, contentView.frame.size };

    if (animated && oldC != nil) {
        oldC.view.alpha = 1.0f;
        newC.view.alpha = 0.0f;
        [self transitionFromViewController:oldC toViewController:newC duration:0.25f options:0 animations:^{

            oldC.view.alpha = 0.0f;
            newC.view.alpha = 1.0f;

         } completion:^(BOOL finished) {
            [oldC removeFromParentViewController];
            [newC didMoveToParentViewController:self];
         }];
    } else {
        [contentView addSubview:newC.view];
        oldC.view.alpha = 0.0f;
        newC.view.alpha = 1.0f;
        [oldC removeFromParentViewController];
        [newC didMoveToParentViewController:self];
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,我之前给出的正则表达式中有一个错误。在正则表达式中,括号需要进行转义,所以在你的模式中的两个括号需要改为`\(`和`\)`。以下是修改后的代码: ```python import re html = ''' <html> <meta http-equiv="Content=-Type" content="text/html; charset=utf-8"/> <head> <link href="http://192.167.1.101/hint.css" rel="stylesheet"></link> </head> <body>[talkid:137031381]2014年4月20日 03:55:45 , <span class="hint-success" data-hint="">2323234</span> 在群 <span class="hint-success" data-hint="">20011</span> 中发言 我们已经是dffwerwer天吧! [talkid:137031382]2014年4月22日 04:45:45 , <span class="hint-success" data-hint="">2323234</span> 在群 <span class="hint-success" data-hint="">20011</span> 中发言 音频 :[<a href="files/24434sfsfsjdfrhf_n.m4a"]>音频</a> [talkid:137031383]2014年4月23日 04:55:45 , <span class="hint-success" data-hint="">2323234</span> 在群 <span class="hint-success" data-hint="">20011</span> 中发言 图片 :[<a href="files/f/f123ftrtrhf_n.jpg"]>图片</a> [talkid:137031384]2014年4月24日 05:55:45 , <span class="hint-success" data-hint="">2323234</span> 在群 <span class="hint-success" data-hint="">20011</span> 中发言 我们已方式方法方式 [talkid:137031385]2014年4月25日 06:55:45 , <span class="hint-success" data-hint="">2323234</span> 在群 <span class="hint-success" data-hint="">20011</span> 中发言 我而对方是否的天吧! </body> </html> ''' pattern = r'\(发送|中发言\)\s*(.*?).*?(音频 :|图片 :).*?(\[.*?\])' matches = re.findall(pattern, html, re.DOTALL) for match in matches: content = match[0] content_type = match[1] file_link = match[2] if content_type == '音频 :': print(f"音频链接地址: {file_link}") elif content_type == '图片 :': print(f"图片链接地址: {file_link}") else: print(f"发言字段: {content}") ``` 请尝试运行修改后的代码,并检查是否有任何错误。如果还有问题,请告诉我。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值