[問題] 多重型態處理的方法
最近想要作一個view,如下
┌───────┐
│ │
│ UILabel │
│ │
│ A │
│ │
│ other UIView │
│ │
│ │
└───────┘
其中 A view (UIView) 的部分想要動態決定是屬於哪種 view
例如 A 可能是 UIImageView 或 UITextView 或 UILabel
我目前的寫法是 定一個 array 裡面存 NSNumber
也就是說目前 index 在array 第 index 個的時候
alloc 出對應的 xxx type View
寫法是 if( index == [NSNumber intValue])
alloc UIImageView
else if( index == [NSNumber intValue])
alloc UILabelView
else
.... alloc 其他 type
然後讓 A = xxx type View.
可是這樣很蠢啊...Orz
請問有甚麼好方法可以把 if-else 給拔掉呢?
謝謝QQ
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.163.3.187
推
10/18 12:53, , 1F
10/18 12:53, 1F
討論串 (同標題文章)
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章