如果,在同一个 UIViewController 里,两个不同的按钮触发了两个不同的 UIActionSheet,然后这两个 UIActionSheet 的 delegate 都是这个 UIViewController 本身,那么大家会用什么样的办法在实现 delegate 的响应方法时区分不同的 UIActionSheet 呢?
或者,有更好的设计模式?
或者,有更好的设计模式?
|
1
我目前在用的一种方式是,为这些不同的 UIActionSheet 分配不同的 tag,然后在 delegate 的响应方法里做判断。
所以我好奇是否还有其他更好的方法? |
|
ydhydhFeb 27, 2012
2
根据 buttonTitle ??
buttonTitleAtIndex |
|
FannFeb 27, 2012
3
同样用 tag 来区分处理,不同的 UIAlertView 也是用 tag 区分。
|
|
fly2neverFeb 27, 2012
4
目前也是tag区分,还发现什么不好
|
|
5
那么,如果就是用 tag 来区分的话,在 tag 的编码上,大家是否有什么好的规则心得可以分享一下呢?
|
|
frooFeb 27, 2012
7
UIActionSheet *sheet1;
UIActionSheet *sheet2; 然后在Delegate中用if来判断 if (actionsheet == sheet1 ){}, if (actionsheet == sheet2 ){} …… 这样可读性应该好一些。 |
|
doskoiFeb 27, 2012
9
TAG可以定义成enum
enum { kAlertView, kInfomationView, kWarningView, kErrorView } 然后tag = Alertview.tag; switch tag, case不同tag做处理 |
|
leveyFeb 27, 2012
10
要么用类的变量,要么用tag,我喜欢后者。as.tag = 0x2001
|
|
linlinqiFeb 27, 2012
12
我试过用actionSheet的title来判断——当它们的标题不一样的时候
|
|
sawyerzhangFeb 27, 2012
13
同意 @froo, 直接在IB里面拉很方便的。
|
|
lldongFeb 27, 2012
15
支持用tag,而且tag是NSInteger类型,能保证存得下一个指针,有时可以利用这点保存一些和该view关联的信息。
|
|
avatasiaFeb 28, 2012
16
public class UIActionSheet
{ public static UIActionSheet Sheet1 = new UIActionSheet ("Sheet1"); public static UIActionSheet Sheet2 = new UIActionSheet ("Sheet2"); private UIActionSheet (string type) { } } UIController(UIActionSheet sheet) { } 随便写的 |
|
eldenFeb 28, 2012
17
Blocks
|
|
lexFeb 28, 2012
18
|