2012-04-04 140 views
0

我想在用戶觸摸圓角矩形按鈕三秒後發出警報顯示,但在運行應用程序時它不起作用(但Xcode說「沒有問題」 )。幾秒鐘後顯示警告視圖

這是我的.h文件:

@interface ViewController : UIViewController { 
} 

-(IBAction)timerAlert:(id)sender; 
-(void)showAlert; 

,這是我實現文件:

@implementation ViewController 

-(IBAction)timerAlert:(id)sender { 

    [NSTimer scheduledTimerWithTimeInterval:3 target:sender selector:@selector(showAlert) userInfo:nil repeats:NO]; 
} 

-(void)showAlert { 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Three seconds have elapsed" message:@"Please return to the app" delegate:self cancelButtonTitle:@"Return" otherButtonTitles:nil, nil]; 
    [alert show]; 
} 

,這是錯誤消息我得到:

2012-04-04 19:25:42.833 DisplayAfterTime[740:f803] 
-[UIRoundedRectButton showAlert]: unrecognized selector sent to instance 0x6b74220 
2012-04-04 19:25:42.837 DisplayAfterTime[740:f803] 
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIRoundedRectButton showAlert]: unrecognized selector sent to instance 0x6b74220' 
*** First throw call stack: (0x13c7022 0x1558cd6 0x13c8cbd 0x132ded0 0x132dcb2 0x94deb6 0x139b936 0x139b3d7 0x12fe790 0x12fdd84 0x12fdc9b 0x12b07d8 0x12b088a 0x11626 0x1edd 0x1e45) terminate called throwing an exception 

等什麼我做錯了嗎?

回答

1

你正在設置定時器發送到錯誤的目標。它應該是自我。