看板 MacDev 關於我們 聯絡資訊
最近想要作一個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
kiii210:[aview class] isEqualToClass:....] ? 10/18 12:53