views:

59

answers:

6

I'm getting a compiler error when i try to build the following code. Its a simple View (UntitledViewController) that has a navbar with a bar button item which calls showPopUp that creates and displays a pop up with my other view (popoverview).

Popoverview has a button which calls hidePopOver which im trying to make close the pop up , but I'm getting this compiler error:

"expected ':' before '.' token"

on this line:

[UntitledViewController.popOver dismissPopoverAnimated:YES];

If i comment out the line of code or put an NSLog it works fine

UntitledViewController

/*--UntitledViewController.h--*/

#import <UIKit/UIKit.h>

@interface UntitledViewController : UIViewController {
    UIPopoverController *popOver;
    IBOutlet UIBarButtonItem *popOverbutton;
}

@property (nonatomic, retain) UIPopoverController *popOver;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *popOverbutton;

-(IBAction)showPopUp;

@end


/*--UntitledViewController.m--*/

#import "UntitledViewController.h"
#import "popoverview.h"

@implementation UntitledViewController
@synthesize popOverbutton, popOver;

-(IBAction)showPopUp {
      popoverview *popView = [[popoverview alloc] initWithNibName:@"popoverview" bundle:nil];
      popOver = [[UIPopoverController alloc] initWithContentViewController:popView];
      [popOver presentPopoverFromBarButtonItem:popOverbutton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
 }
 ...

popoverview

/*--popoverview.h--*/   

#import <UIKit/UIKit.h>

@interface popoverview : UIViewController {

}
-(IBAction)hidePopOver;
@end


/*--popoverview.m--*/

#import "popoverview.h"
#import "UntitledViewController.h"

@implementation popoverview
-(IBAction)hidePopOver {
    [UntitledViewController.popOver dismissPopoverAnimated:YES]; (ERROR "expected ':' before '.' token")
}
+1  A: 

Since "dismissPopoverAnimated:" is an instance method, you need to do something like:

[self.popOver dismissPopoverAnimated:YES];
Kevin Sylvestre
A: 

You need to create an instance of UntitledViewController before you can access its properties.

UntitledViewController* myInstance = [[UntitledViewController alloc] init];
[myInstance.popOver dismissPopoverAnimated:YES];
willcodejavaforfood
A: 

You are trying to access the popOver propert of the class UntitledViewController. Classes don't have properties or instance variables. You need an instance of the class UntitledViewController.

So you need add a UntitledViewController instance to popoverview and use that.

Mark
A: 

you havent declared UntitledViewController in your popoverview class.

If you want to hide that specific popOver from popoverview class, you need to have a reference to the UntitledViewController instance that has that specific popOver.

Aside: work on your naming conventions.

Jesse Naugher
A: 

In this line:

[UntitledViewController.popOver dismissPopoverAnimated:YES];

You are referencing the class UntitledViewController, not an instance of that class.

kubi
+1  A: 

UntitledViewController is a class. You need an instance if you want to access a property.

UntitledViewController * vc = [ UntitledViewController new ];

Then you can access the property on the instance:

vc.popOver

Objective-C does not support class variables, nor class properties.

Macmade