从AlertView按钮切换视图

时间:2010-10-04 12:00:27

标签: objective-c cocoa-touch ios4 uialertview

申请

它有3个视图视图A,B,C。 视图B上有警报,上面有2个按钮。

我的工作是:

我从视图A转到视图B.在B上,我点击警报按钮将我带回视图A.

问题:

当我点击按钮再次转到View B时,它会给出与计时器的“isValid”属性相关的错误。定时器在视图B中声明并使用 在其他情况下,当我使用自定义按钮切换A& B然后它工作正常。

我收到错误的行 BOOL dec = [timer isValid];

可能是什么错?


警报视图按钮的代码是开关视图

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

        if(buttonIndex == 0)
        {
             [self dismissModalViewControllerAnimated:YES];
          }
 }

在切换到同一视图时出现问题的代码

 -(void)viewWillAppear:(BOOL)animated
 {

        BOOL dec = [timer isValid];

        NSLog(@"TIMER CHECK");

       if (dec == YES)
       {
           [timer invalidate];
       }    
 }

在NSLOG中显示的错误是:

 -[__NSCFType isValid]: unrecognized selector sent to instance 0x5996870
2010-10-04 15:49:00.630 sqlite[5263:207] *** Terminating app due to uncaught exception     'NSInvalidArgumentException', reason: '-[__NSCFType isValid]: unrecognized selector sent to   instance 0x5996870'
 *** Call stack at first throw:
(
    0   CoreFoundation                      0x023e9919 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x025665de objc_exception_throw + 47
    2   CoreFoundation                      0x023eb42b -[NSObject(NSObject) does    NotRecognizeSelector:] + 187
    3   CoreFoundation                      0x0235b116 ___forwarding___ + 966
    4   CoreFoundation                      0x0235acd2 _CF_forwarding_prep_0 + 50
    5   sqlite                              0x0000393b -[sqliteViewController viewWillAppear:] + 622
    6   UIKit                               0x0055775d -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 5402
    7   UIKit                               0x0036e769 -[UIViewController presentModalViewController:withTransition:] + 2937
    8   UIKit                               0x00367a5e -[UIViewController _tryRecursivelyPresentModalViewController:withTransition:] + 134
    9   UIKit                               0x0036df42 -[UIViewController presentModalViewController:withTransition:] + 850
     10  sqlite                              0x00005d8a -[StartPageViewController startQuiz:] + 68
    11  UIKit                               0x002c2e14 -[UIApplication sendAction:to:from:forEvent:] + 119
    12  UIKit                               0x0034c6c8 -[UIControl sendAction:to:forEvent:] + 67
    13  UIKit                               0x0034eb4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    14  UIKit                               0x0034d6f7 -[UIControl touchesEnded:withEvent:] + 458
    15  UIKit                               0x002e62ff -[UIWindow _sendTouchesForEvent:] + 567
    16  UIKit                               0x002c81ec -[UIApplication sendEvent:] + 447
    17  UIKit                               0x002ccac4 _UIApplicationHandleEvent + 7495
    18  GraphicsServices                    0x02c04afa PurpleEventCallback + 1578
    19  CoreFoundation                      0x023cadc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    20  CoreFoundation                      0x0232b737 __CFRunLoopDoSource1 + 215
    21  CoreFoundation                      0x023289c3 __CFRunLoopRun + 979    
    22  CoreFoundation                      0x02328280 CFRunLoopRunSpecific + 208 
    23  CoreFoundation                      0x023281a1 CFRunLoopRunInMode + 97
    24  GraphicsServices                    0x02c032c8 GSEventRunModal + 217
    25  GraphicsServices                    0x02c0338d GSEventRun + 115
    26  UIKit                               0x002d0b58 UIApplicationMain + 1160
    27  sqlite                              0x00002910 main + 102
    28  sqlite                              0x000028a1 start + 53
)
 terminate called after throwing an instance of 'NSException'

1 个答案:

答案 0 :(得分:0)

得到它的原因。我试图使已经失效的计时器无效。谢谢无论如何