2011-12-20 40 views
1

面對我職業生涯中一些奇怪的時刻。我在我的UIViewController中有一些uitextfield和一個uitextview ....在模擬器和iPhone 4 iOS v 4.3.5上一切正常。但在iPhone 4 iOS v 4.0.1中,有時會刷新整個視圖。這意味着有時我的uitextfields & uitextview丟失的文字後,從相機採摘圖像.....UITextView&UITextField在iPhone設備從相機中選擇圖像時刷新刷新

爲解決這個我的嘗試是當視圖消失我保存的值在一些數組.......當視圖確實出現我顯示數組值到文本框.....它的模擬器也很好。但是這一次我的應用程序在iPhone 4 iOS v 4.0.1上運行。

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 
    NSLog(@"title : %@",actionSheet.title); 
    if (![actionSheet.title isEqualToString:@"Success"] && ![actionSheet.title isEqualToString:@"Error"] && ![actionSheet.title isEqualToString:@"خطأ"]) { 
     if(buttonIndex == 1) { 
      if([UIImagePickerController isSourceTypeAvailable: 
       UIImagePickerControllerSourceTypePhotoLibrary]) 
      { 
       UIImagePickerController *picker= [[UIImagePickerController alloc]init]; 
       picker.delegate = self; 
       picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
       [self presentModalViewController:picker animated:YES]; 
       [picker release]; 
      } 
     } else { 
      UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
      picker.delegate = self; 
      picker.allowsImageEditing = YES; 
      picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
      [self presentModalViewController: picker animated:YES]; 
      [picker release]; 
     } 
    } 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo { 

    float actualHeight = img.size.height; 
    float actualWidth = img.size.width; 
    float imgRatio = actualWidth/actualHeight; 
    float maxRatio = 320.0/480.0; 

    if(imgRatio!=maxRatio){ 
     if(imgRatio < maxRatio){ 
      imgRatio = 480.0/actualHeight; 
      actualWidth = imgRatio * actualWidth; 
      actualHeight = 480.0; 
     } 
     else{ 
      imgRatio = 320.0/actualWidth; 
      actualHeight = imgRatio * actualHeight; 
      actualWidth = 320.0; 
     } 
    } 
    CGRect rect = CGRectMake(0.0, 0.0, actualWidth, actualHeight); 
    UIGraphicsBeginImageContext(rect.size); 
    [img drawInRect:rect]; 
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    if(imageCount == 1){ 
     self.firstImage = image; 
     self.previewImage1.image =firstImage; 
    }else if(imageCount == 2){ 
     self.secondImage = image; 
     self.previewImage2.image =secondImage; 
    }else if(imageCount == 3){ 
     self.thirdImage = image; 
     self.previewImage3.image =thirdImage; 
    }else if(imageCount == 4){ 
     self.fourthImage = image; 
     self.previewImage4.image =fourthImage; 
    } 
    [myImageNames replaceObjectAtIndex:imageCount-1 withObject:@"Assigned"]; 

    [[picker parentViewController] dismissModalViewControllerAnimated:YES]; 
} 
+0

粘貼你有問題的代碼。 – WrightsCS 2011-12-20 04:49:43

+0

你的意思是「我的應用程序被困住」。你的意思是應用程序界面凍結,在2-3秒內沒有響應觸摸,然後繼續正常工作? – 2011-12-20 17:55:33

+0

只是忽略了卡住....我有時從我的uitextfield空白(而不是每次)僅在從iPhone 4 iOS v4.0.1相機拍攝圖像後,但不是在模擬器和iPhone 4上IOSv 4.3.5 – 2011-12-20 20:57:33

回答

1

解決..從設備中刪除的應用程序。然後重新啓動設備並再次安裝生成.... 現在沒有問題,從相機採摘圖像上的uitextfield刷新.. 寒冷的傢伙.... :-)