2016-08-11 11 views
1

イメージピッカーを使用してローカルデバイスギャラリーからイメージをピッキングしていますが、xcodeを使用してコアデータを使用してイメージが保存され、あなたが名前と説明フィールドまたはストア・オブジェクトの作成の問題については言及しなかったので7.3、ios9および2.2コアデータを使用してテーブルビューセルでイメージを更新する方法

if isUpdate == true{ 
      print("object id \(self.store?.objectID)") 
      self.store?.sName = name.text 
      self.store?.sDescription = desc.text 
      //save.setTitle("my text here", forState: .Normal) 
      let img = UIImage(named: "image.jpeg") 
      let imgData = UIImageJPEGRepresentation(img!,1) 
      self.store?.sImage = imgData 
      do { 
       try appdelegate.managedObjectContext.save() 
       self.navigationController?.popViewControllerAnimated(true) 
      } catch let error as NSError { 
       print("Could not save \(error), \(error.userInfo)") 
      } 

     }else{ 
      //get the description of the entity 
      let storeDescription = NSEntityDescription.entityForName("Store",inManagedObjectContext: appdelegate.managedObjectContext) 

      //we create managed object to be inserted to core data 
      let store = EventsandnotesStore(entity : storeDescription!,insertIntoManagedObjectContext:appdelegate.managedObjectContext) 
      store.sName = name.text 
      store.sDescription = desc.text 
      // 
      let img = UIImage(named: "image.jpeg") 

      let imgData = UIImageJPEGRepresentation(img!,1) 

      store.sImage = imgData 
      do { 
       try appdelegate.managedObjectContext.save() 
       self.navigationController?.popViewControllerAnimated(true) 
      } catch let error as NSError { 
       print("Could not save \(error), \(error.userInfo)") 
      } 

      } 


    } 

答えて

0

迅速、私はすべてが働いたと仮定していて、あなたはCoreDataプロセスでOKです。

チェックするべき点は、JPEG変換コールの整数値1です。それはフロートでなければならないので、コールで1.0を試してください。私はXCodeに捕まられなかったことに驚いています。それが問題を引き起こすかどうかは不明です。

私は、UIImageJPEGRepresentation呼び出しが他の理由で失敗し、nil値を返すことができないということで、変換で発生する可能性のあるその他の問題があります(例:CIImageをUIImageに直接変換したときCGImageを使っていればうまくいきました。すべてのことを考えれば、呼び出しの結果を確認する必要があります。

guard let thumbnailData = UIImageJPEGRepresentation(thumbnailUI, Set.shared.jpegQuality) else 
    { 
     logError(#file, line: #line, column: #column, function: #function, description: "JPG Conversion Error - thumbnail") 
     return nil 
    } 

をそれはあなたがピッカーから取得している画像にチェックする必要があります失敗だ場合:次のように私はガードの文とカスタムロガーを使用します。

データベース側で問題が発生している場合は、ViewController(controllerWillChangeContentなど)にTableViewデリゲート関数を含めてください。イメージを含むレコードが変更されたときにconfigureCellメソッドが呼び出されるようにする必要があります。

これは私が最初にやるべきことです。

+0

私は誤って別のイメージに同じ名前を付けましたが、logErrorを使って修正しました。 –

+0

うれしかった –

関連する問題