预期的标识符或“(”

时间:2013-07-08 13:12:14

标签: objective-c

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface ViewController : UIViewController<CLLocationManagerDelegate>
{           
    CLLocationManager *_locationManager;
}
@property (strong, nonatomic) IBOutlet UISwitch *locationUpdatesSwitch;
@property (strong, nonatomic) IBOutlet UILabel *locationInformationLabel;

- (IBAction)toggleLocationUpdates:(id)sender;
{ //EXPECTED IDENTIFIER OR "(" 
    if (self.locationUpdatesSwitch.on == YES)

{
    if ([CLLocationManager locationServicesEnabled] == NO)
    {
        UIAlertView *locationServicesDisabledAlert =
        [[UIAlertView alloc] initWithTitle:@"Location Services Disabled"
                                   message:@"This feature requires location services. Enable it in the privacy settingson your device"
                                  delegate:nil
                         cancelButtonTitle:@"Dismiss"
                         otherButtonTitles:nil];
        [locationServicesDisabledAlert show];
        self.locationUpdatesSwitch.on = NO;
        return;
        }
}

    else

    {
    // Switch was turned Off
}
}

尝试使用基于xcode项目的小型核心位置。谁有人帮我出去?我没看到我错过了什么,但我得到了一个“预期的标识符或”(“”之后的错误 - (IBAction)toggleLocationUpdates:(id)sender;

提前致谢!

2 个答案:

答案 0 :(得分:2)

您无法在@interface部分编写函数体。将它们移至.m中的@implementation文件。

答案 1 :(得分:1)

除了Tom的回答你需要在your.m文件中删除你的ibaction方法的;

变化

- (IBAction)toggleLocationUpdates:(id)sender;

- (IBAction)toggleLocationUpdates:(id)sender {}