[英]Calling UIAlertView delegate method crashed
我有一個viewController類A,該類具有創建UIAlertView並實現UIAlertView Delegate方法的方法,還有一個用於處理日志記錄和聯網的NSObject模型類B。 在類B中,僅分配一個A類實例,然后調用A的方法。警報視圖正常顯示,但是當我單擊“確定”按鈕時,它只是崩潰了。 我想單擊“確定”按鈕重新打開鍵盤,讓用戶在失敗后繼續登錄。 (已在頭文件中聲明了UIAlertView協議。)
在viewcontroller類A中:
- (void)displayAlertViewString:(NSString *)string
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Login Failured!"
message:string
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Ok", nil];
[alert show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:@"Ok"])
{
//reopen the keyboard let user continue login.
[self.passwordField becomeFirstResponder[;
}
在模型類B中,我在AFNetworking
的failure block
中調用了顯示警報視圖方法。
failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"%@", error);
RDLoginViewController *loginViewController = [[RDLoginViewController alloc] init];
[loginViewController displayAlertViewString:@"The entered email or password was incorrectly!"];
調試器中沒有任何信息,Xcode只是停留在線程視圖上。 誰能幫我解決這個問題? 謝謝。
執行完故障塊后,由於沒有人對其強大的引用,您的loginViewController
將從內存中釋放。
當alertView嘗試訪問它的委托時,它崩潰了,因為它的委托不再存在於內存中。
建議您閱讀《 高級內存管理編程指南》 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.