2016-03-28 16 views
-1

değil, bu yüzden ben oluşturmak göreve içine kullanıcı gönderin:Denemesi sunmak <UIAlertController:> üzerine <ViewController:> kimin görünüm Ben ResearchKit kullanarak bir proje üzerinde çalışıyorum pencere hiyerarşi

let taskViewController = ORKTaskViewController(task: SurveyTask, taskRunUUID: nil) 
taskViewController.delegate = self 
presentViewController(taskViewController, animated: true, completion: nil) 

kullanıcı anket ile bittiğinde, o gider:

func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?) { 
    switch reason { 
     case .Completed: 

... } Burada

Benönce uyarı gösterme denediğimde bir sorunla karşılaşırsanız ViewController üzerinde ...: UIAlertController sunmak

Denemesi:

taskViewController.dismissViewControllerAnimated(true, completion: nil) 
aşağıda hatayı alıyorum ... kimin görünüm penceresi hiyerarşi

yılında I nasıl Herhangi bir fikir değildir ViewController görevden alınmadan önce uyarıyı sunabilir mi?

Ben uyarı için aşağıdaki kullanın:

let alertView = UIAlertController(title: "Houps", message: "Could not connect to the server.", preferredStyle: .Alert) 
alertView.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil)) 
presentViewController(alertView, animated: true, completion: nil) 

EDIT: kod aşağıdaki gibidir:

if let httpResponse = response as? NSHTTPURLResponse { 
       print("HTTP response: \(httpResponse.statusCode)") 
       if httpResponse.statusCode == 201 { 
        taskViewController.dismissViewControllerAnimated(true, completion: nil) 
       } 
      } else { 
       print("No HTTP response") 
       let alertView = UIAlertController(title: "Houps", message: "Could not connect to the server.", preferredStyle: .Alert) 
       alertView.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil)) 
       presentViewController(alertView, animated: true, completion: nil) 

      } 
+0

size uyarı kontrolörü "OK" butonuna tıklamak görünümü denetleyicisi görevden Could itiraz ORKTaskViewController? –

+0

Henüz görevden almak istemiyorum, önce uyarıya geçmek istiyorum. İşten çıkarılma gayet iyi çalışıyor. Sorun, uyarıyı gösteriyor. – asheyla

+1

Evet ve @ j.f. uyarıda "Tamam" a dokunduğunuzda reddetmek için söylüyor. – tktsubota

cevap

0

Sen taskViewController üzerinde presentViewController çağırmalıdır:

taskViewController.presentViewController(alertView, animated: true, completion: nil) 
+0

olan üzerinde sunma girişimi Evet, işte bu! İşe yarıyor! Teşekkür ederim Stefan! – asheyla

0

Sen sunulması için bu

UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(yourAlertController, animated: true, completion: nil) 

deneyebilirsiniz UIAlertController.

1

httpResponse tanımı hangi nesneyi içerir? PresentViewController() çağrısı, görüntünün yanıt geldiğinde görünüm hiyerarşisinde artık bulunmayan bir görünüm denetleyicisi örneğinde, örtülü olarak kendini yakalama gibi görünüyor.

İlgili konular