2016-08-13 1 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과 같은 사전이 있습니다.

다음보기에서는 사전의 모든 데이터에 액세스하고 사전에있는 이미지 중 하나를 사용하여 단추의 배경 이미지를 설정하려고합니다. 요리사의 개체 ID 내가 배경으로 같은 행에있는 이미지를 설정하려는 사전 내부 개체 ID를 일치하도록 할 때 는 그래서 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 

    } 

} 

있습니다.

하지만 그렇지 않습니다!

당신은 내가 이미지를 인쇄하려고 참조하면 if statement가 정확하고 내가

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

을 얻을 때 어떻게 배경이 이미지를 설정하는 것이 가능하지만?!?!

고맙습니다. 이 Stroyboard이 유형을 변경에서 경우

+0

버튼이 프로그래밍 방식으로 생성 되었습니까? – Sofeda

답변

1

은이 프로그램

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

를 버튼 형식의 사용자 정의 만든 설정합니다.

+0

아 .. 네, 그게 해결책이었습니다! –

관련 문제