)之前的预期; if语句中的标记

Mik*_*yev 0 if-statement objective-c

我在头文件中定义了一个常量

#define kPortraitMode 1
#define kLandscapeMode 2

Byte:viewOrientation;//this is my ivar that'll keep interface orientation info
Run Code Online (Sandbox Code Playgroud)

在willAutorotateToInterfaceOrientation:withDuration:方法我说:

if(toInterfaceOrientation==UIInterfaceOrientationPortrait){
   self.viewOrientation=kPortraitMode;
}
else{
    self.viewOrientation=kLandscapeMode;        
Run Code Online (Sandbox Code Playgroud)

然后在Table View数据源方法tableview:height:forIndexPath方法我说:

double height;
if (self.viewOrientation==kPortraitMode){//Here I get the error) expected before token;

height=263.0;
}
else{
height=320;
}
return height;
Run Code Online (Sandbox Code Playgroud)

我的问题是我在这里做错了什么来获得这个编译错误?这只是一个简单的表达.

Ana*_*mar 6

你确定定义的常量是这样的

#define kPortraitMode 1
#define kLandscapeMode 2
Run Code Online (Sandbox Code Playgroud)

而不是这样的:

#define kPortraitMode 1;
#define kLandscapeMode 2;
Run Code Online (Sandbox Code Playgroud)

该行中的错误是因为;在关闭if条件之前您有一个错位的语句终止符.因此,如果您;在定义的常量中,可能是错误的原因.