English 中文(简体)
iphone中的枚举不起作用
原标题:Enumeration in iphone is not working
  • 时间:2011-02-09 16:26:42
  •  标签:
  • iphone
  • enums

我正在开发一个iphone应用程序,其中我有3个类=>;main类、abc类、pqr类。在主视图上,我有图像视图,我正在其上显示图像。当用户触摸主视图上的图像中心时,将推送新视图(取决于下面提到的条件)

a) if user came from abc view then new view will not be pushed

b) if user came from pqr view then i have to push new view .

我的问题是如何检测用户从哪个视图进入主视图。

我创建了一个类,在.h文件中有以下代码

typedef enum {
        abcViewSelected,
        pqrViewSelected
} SelectedViewType;

@interface Enumeration : NSObject {
    SelectedViewType selectedViewType;
}

@property(nonatomic) SelectedViewType selectedViewType;

在里面我有m文件

@synthesize selectedViewType;

当用户从abcView&;pqrView,我正在推送主视图&;在didSelectRowAtIndexPath中设置视图类型,如下所示:-

enumObj.selectedViewType = abcViewSelected;

enumObj.selectedViewType = pqrViewSelected;

在主视图的触摸开始方法中,我通过写下以下内容来比较选择了哪个视图

if(enum.selectedViewType == pqrViewSelected) => push new view 

否则什么也不做。

但这不是竞争;在任何情况下都不会推出新的视图。我已经到处导入了所有必需的头文件。

请帮帮我。。。。提前谢谢。

最佳回答

问题一定出在这一行:

if(enum.selectedViewType = pqrViewSelected)

在这里,您不比较当前类型值,而是将pqrViewSelected分配给它(您有=而不是==)。尝试将该行更改为:

if(pqrViewSelected == enum.selectedViewType){
    // push view
}

请注意,将常量表达式作为比较中的第一个参数使得不可能错误地使用赋值(=)而不是比较(==)。

问题回答

暂无回答




相关问题
Finding the Highest Value in an Enumeration

I m writing a method which determines the highest value in a .NET enumeration so I can create a BitArray with one bit for each enum value: pressedKeys = new BitArray(highestValueInEnum<Keys>());...

Conversion of Enum to Enumerable

To convert Enum to Enumerable ,I use public enum Flags { Trivial=1, Minor, Major, Critical } IEnumerable<int> n = Enumerable.Range((int)Flags.Trivial, (...

Subclass check, is operator or enum check

A couple of friends was discussing the use of inheritance and how to check if a subclass is of a specific type and we decided to post it here on Stack. The debate was about if you should implement a ...

Enum scoping issues

I try to keep things as local as possible, so I put enums at class scope, even if they are shared between two classes (I put it in the class that "goes better" with it.) This has worked out great, but ...

How do I sort enum members alphabetically in Java?

I have an enum class like the following: public enum Letter { OMEGA_LETTER("Omega"), GAMMA_LETTER("Gamma"), BETA_LETTER("Beta"), ALPHA_LETTER("Alpha"), private final String ...

C++ enum value initialization

I have an enum declared in my code as: enum REMOTE_CONN { REMOTE_CONN_DEFAULT = 0, REMOTE_CONN_EX_MAN = 10000, REMOTE_CONN_SD_ANNOUNCE, REMOTE_CONN_SD_IO, REMOTE_CONN_AL, ...

WCF: Enforce equal DataContracts on both sides

I m wondering if it is possible to have WCF make sure that the DataContracts on both sides of a connection are exactly the same (and throw an exception when trying to connect if they are not). For ...

热门标签