ios - how to access variables inside an enum? -
class detailsviewcontroller: uiviewcontroller { @iboutlet weak var summarybutton: uibarbuttonitem! @iboutlet weak var commentarybutton: uibarbuttonitem! enum viewstate: int { case summary case commentary func setvisibility() { switch (self) { case summary: summarybutton.enabled = true commentarybutton.enabled = false case commentary: summarybutton.enabled = false commentarybutton.enabled = true } } } }
i not able access summarybutton , commentarybutton: gives error saying "detailsviewcontroller.type not have member named summarybutton"
how access summarybutton , commentarybutton?
solution: worked me
enum viewstate { case summary case commentary } class detailsviewcontroller: uiviewcontroller { @iboutlet weak var summarybutton: uibarbuttonitem! @iboutlet weak var commentarybutton: uibarbuttonitem! var currentstate: viewstate = .summary { didset { switch (currentstate) { case .summary: summarybutton.enabled = true commentarybutton.enabled = false break case .commentary: summarybutton.enabled = false commentarybutton.enabled = true break default: break } } }
it seems me solution backwards. it's strange have enum own iboutlets buttons.
i move outlets , setvisibility method outside of enum , detailsviewcontroller. create instance variable currentviewstate of type viewstate in detailsviewcontroller, , make setvisibility method switch based on currentviewstate.
Comments
Post a Comment