2016-08-13 6 views
2

から背景イメージが再度設定されていません。UIButton Singleton Dictionary

だから私はちょうどRecipes.swift

static let sharedInstance = Recipes() 

var imagesOfChef = [Int : chefImages]() 
struct chefImages { 
     var objidChef: String! 
     var imageChef: UIImage! 
    } 

ファイルに次のコード と辞書のシングルトン例を終えたとプロセスが終了したときに、私はこのコード

let singleton = Recipes.sharedInstance 
singleton.imagesOfChef = self.imagesOfChef 

を持っていますにはimagesOfChefと同じ辞書があります。

次のビューでは、辞書のすべてのデータにアクセスし、その辞書の画像の1つを使用してボタンの背景画像を設定します。 cellForItemAtIndexPathだからで、私は、次のコード

let test = userPointer.objectId 
    let otherReferenceToTheSameSingleton = Recipes.sharedInstance 




for i in 0...otherReferenceToTheSameSingleton.imagesOfChef.count - 1 { 
    print(otherReferenceToTheSameSingleton.imagesOfChef[i]!.objidChef) //it prints the object id's of the Chef normally 

    if otherReferenceToTheSameSingleton.imagesOfChef[i]!.objidChef == test! { 
     print("done") 
     print(otherReferenceToTheSameSingleton.imagesOfChef[i]!.imageChef) 
     cell.avatarOutlet.setImage(otherReferenceToTheSameSingleton.imagesOfChef[i]!.imageChef, forState: .Normal) //but it doesnt set the Image as a background 

    } 

} 

を持っているので、シェフのオブジェクトIDは、iが背景と同じ行にある画像を設定する辞書内にあるオブジェクトIDと一致する場合。

しかし、それはありません!

あなたは私が画像を印刷しようと見たらif statementが正しいと私は

<UIImage: 0x1582c9b50>, {60, 60} 

を取得するときにどのように背景として、この画像を設定することが可能ですが??!?!

ありがとうございます!それはStroyboardそこから種類を変更する場合には、それがプログラム

let button = UIButton(type: UIButtonType.Custom) as UIButton 

作成された場合

+0

ボタンはプログラムによって作成されていますか? – Sofeda

答えて

1

は、ボタン型のカスタムを設定します。

+0

ああ..はい、それは解決策でした! –