2016-03-28 7 views
0

commentimageの属性を持つreportというカスタムオブジェクトがあります。 prepareForSegue -Methodでは簡単にreport.comment = "Comment"と呼ぶことができます。これはうまくいきます...問題ありません。次に、画像を に設定し、新しいViewControllerが表示されたら、画像は表示されませんが、コメントが設定されています。カスタムオブジェクトにUIImageを保存できません

if let imageData = valueDict.valueForKey("image") 
{ 
    print(imageData) 
    print("Before processing: \(report.image)") //report.image has a standard value; UIImage() 
    report.image = UIImage(data: imageData as! NSMutableData, scale: 1.0)! 
    print("After processing: \(report.image)") 
} 

私が最初print() -statementは私に、元の画像データを示していると確信しています。私は<ffd8ffe0 00104a46 49460001 01000048... and so onのようなものを手に入れます。私もエラーは表示されません - メッセージは表示されません。変換方法が機能していないようです。変換後、私はこのような何かを得る<UIImage: 0x7ff6f858bda0>, {1080, 1080}report.image = UIImage(named: "defaultPhoto.png")!のような静止画を設定しても、画像は表示されません。

私はまた、次の呼び出し

report.image = UIImage(data: valueDict.valueForKey("image") as! NSData)! 
report.image = (valueDict.objectForKey("image") as? UIImage)! 
report.image = UIImage(data: valueDict.objectForKey("image")) 
report.image = valueDict["image"] as! UIImage 

を試みたが、何も作業していません。 したがって、主な質問は、なぜ変換メソッドが期待どおりに機能しないのかです。 プロジェクトを知らない人には間違っていると言われていますが、私がチェックしたり探すことができるヒントや助言があります。 何か助けていただければ幸いです。

編集:

私のSegue-Methodの準備は次のようになります。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) 
    { 

     let dtvc: DetailReportTableViewController = segue.destinationViewController as! DetailReportTableViewController 

     let indexPath = tableView.indexPathForSelectedRow 

     let cell = tableView.cellForRowAtIndexPath(indexPath!) as! MyReportsTableViewCell 
     print("The ReportNumber is: \(cell.reportNumber)") 

     for singleReport in listOfAllReports 
     { 
      if singleReport.key as! String == cell.reportNumber 
      { 
       print("Bericht gefunden.") 
       let valueDict = singleReport.value as! NSDictionary 

       report.category = valueDict.objectForKey("category") as! String 
       report.comment = valueDict.objectForKey("comment") as! String 


       if let dateTime = valueDict.objectForKey("date") 
       { 
        let df = NSDateFormatter() 
        df.dateFormat = "dd-MM-yyy HH:mm:ss" 

        report.timestamp = df.dateFromString(dateTime as! String)! 
       } 

       if let locationData = valueDict.valueForKey("location") 
       { 
        report.locationData.längengrad = locationData.objectAtIndex(0) as! Double 
        report.locationData.breitengrad = locationData.objectAtIndex(1) as! Double 
       } 

       if let imageData = valueDict.valueForKey("image") 
       { 
        print(imageData) 
        print("Before processing: \(report.image)") //report.image has a standard value; UIImage() 
        report.image = UIImage(data: imageData as! NSMutableData, scale: 1.0)! 
        print("After processing: \(report.image)") 
       } 

      } 

     } 
     print("Category: \(report.category)") 
     print("Datum: \(report.timestamp)") 
     print("Location: \(report.locationData)") 
     print("Comment: \(report.comment)") 
     print("Image: \(report.image)") 

     dtvc.report = report 

    } 
+0

prepareForSegueの外観はどうですか? – beyowulf

+0

私の投稿を編集して私のprepareForSegue-Methodを表示しました – user1895268

+0

report.imageを表示するコードは何ですか? – beyowulf

答えて

0

私は、静的な画像を設定しても

なら...イメージが

が真であることが示されていない、問題はUIImageViewではなく、画像そのものと思われます。

Iは

UIImageかなり確信している:0x7ff6f858bda0、{1080 1080}

は、メモリ位置、および画像の大きさを示しています。 (あなたの画像は1080x1080だと思っていますか?)だから、画像を正しく作っていると思います。表示されていません。

画像ビューが他のビューの下ではなく、ペン先に正しく接続されていることを確認してください。

+0

あなたの答えをありがとう、その奇妙な。値 'UIImage:0x7ff6f858bda0、{1080、1080}'は正しいとは言えません。私は元のデータを知っているから。だから私は 'report.image = imageData 'を呼んでいますが、' report.image'は 'imageData'とは全く異なる値を持っています。しかし、もう一度imageViewをチェックします。 – user1895268

+1

イメージビューを表示することはできますか? – PeejWeej

+0

うわー、私はそれを知った。私はあなたが提案したように私のコードをチェックした。画像ビューではありませんでした。宛先ビュー・コントローラーに行が1行欠けていました。私は推測する前に多くの部品をコメントし、何とか私は輸入されたラインを削除しました。だから、配分がありませんでした。みなさんありがとうございました – user1895268

関連する問題