property implementation must have its declaration in interface error - properties

"property implementation must have its declaration in interface" error
I have this error coming up and I am new to xcode so I am unsure what to do.
I had lots of code in a class, then i moved it to a different class and now I have numerous errors. Which dont make sense, as everything looks as it should.
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize MenuScreenButton;
#synthesize HowToPlayButton;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)HowToPlayButtonPressed:(id)sender
{
HowToPlayViewController *HowToPlayView=[[HowToPlayViewController alloc]initWithNibName:nil bundle:nil];
HowToPlayView.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentViewController:HowToPlayView animated:YES completion:NULL];
}
-(IBAction)MenuScreenButtonPressed:(id)sender
{
MenuScreen *MenuScreenView=[[MenuScreen alloc]initWithNibName:nil bundle:nil];
MenuScreenView.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentViewController:MenuScreenView animated:YES completion:NULL];
}
#end
Below is the .h file:
#import <UIKit/UIKit.h>
#import "HowToPlayViewController.h"
#import "MenuScreen.h"
#interface ViewController : UIViewController
{
IBOutlet UIButton *HowToPlayButton;
IBOutlet UIButton *MenuScreenButton;
}
#property(retain,nonatomic) IBOutlet UIButton *MenuScreenButton;
#property(retain,nonatomic) IBOutlet UIButton *HowToPlayButton;
-(IBAction)HowToPlayButtonPressed:(id)sender;
-(IBAction)MenuScreenButtonPressed:(id)sender;
#end

Related

Pop up not Dismissing when i click button in logout

I am using pop over button to Signout a page back to Root view controller. i successfully came back to root view controller but pop up not dismissing. It stays on the Root view controller Here is my code
POPOVERVIEW CONTROLLER.H
#protocol MJSecondPopupDelegate;
#import <UIKit/UIKit.h>
#import "LoginViewController.h"
#import "TimeTableViewController.h"
#class TimeTableViewController;
#interface PopOverViewController : UIViewController <UIPopoverControllerDelegate>
{
// UIPopoverController *popoverController;
}
#property (assign, nonatomic) id <MJSecondPopupDelegate>delegate;//ede ga
#property(strong,nonatomic) UIPopoverController *popoverController;
#property(nonatomic,strong)TimeTableViewController *TimeObj;
-(IBAction)logOut:(UIButton *)sender;
#end
#protocol MJSecondPopupDelegate<NSObject>
#optional
- (void)cancelButtonClicked:(PopOverViewController*)secondDetailViewController;
#end
POPOVERVIEW CONTROLLER.M
#import "PopOverViewController.h"
#interface PopOverViewController ()
#end
#implementation PopOverViewController
#synthesize delegate,TimeObj,popoverController;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)SignOut{
NSLog(#"protocol");
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(#"delegate value is %#",self.delegate);
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)logOut:(UIButton *)sender{
if (self.delegate && [self.delegate respondsToSelector:#selector(cancelButtonClicked:)])
{
[self.delegate cancelButtonClicked:self];
[self.popoverController dismissPopoverAnimated:YES];
}
}
MAINVIEW CONTROLLER.H
#import <UIKit/UIKit.h>
#import "NotesandReminders.h"
#import "Cell.h"
#import "SWRevealViewController.h"
#import "AvailableSessionViewController.h"
#import "ServiceConnector.h"
#import "AppDelegate.h"
#import "PopOverViewController.h"
#import "UIViewController+MJPopupViewController.h"
#class NotesandReminders;
#class PopOverViewController;
#protocol Popupprotocol <NSObject>
#optional
-(void)SignOut;
#end
#interface TimeTableViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate,MJSecondPopupDelegate>{
}
MAINVIEWCONTROLLER.M
#import "AvailableSessionViewController.h"
#interface TimeTableViewController ()
#end
#implementation TimeTableViewController
#synthesize pc,myCounterLabel,cancelSessionButtonOutlet,userButtonOutlet,saveButtonOutlet,timerr,collectionData,cancelSession,jsonData,secondviewcontroller,popoverController;
#synthesize startWeek,endWeek,startDateLabel,endDateLabel,todaysDate,startDate,endDate,dateForMatching,startDateToCall,endDateToCall;
#synthesize blueBarOutlet;
BOOL isLongPressed ;
int hours, minutes, seconds;
int secondsLeft;
int valueForBlueBar;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
// This method runs first when the screen is displayed
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"POPSegue"]) {
PopOverViewController* userViewController = [segue destinationViewController];
userViewController.delegate=self;
}
}
I am creating Pop over just by cntrl drag to the view controller and selecting PopOver modally
After the following line:
[self.popoverController dismissPopoverAnimated:YES];
add
[self.popoverController.contentViewController.navigationController
popToRootViewControllerAnimated:YES];
This is how i managed to get rid of it
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"POPSegue"]) {
// settings popover is the global variable for --> UIPopoverController *settingsPopOver;
settingsPopOver = [(UIStoryboardPopoverSegue *)segue popoverController];
_secondviewcontroller = (PopOverViewController *)settingsPopOver.contentViewController;
_secondviewcontroller.delegate = self;
}
}

Missing context for method declaration?

I am trying to create an app and when I added this IBAction, it gave me the error Missing context for method declaration. I have looked up how to fix this but I am a bit confused since I am a beginner. The errors appear in my .m file:
#import "QRscannerSecondViewController.h"
#end
#interface QRscannerSecondViewController ()
#end
#implementation QRscannerSecondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"Info", #"Info");
self.tabBarItem.image = [UIImage imageNamed:#"second"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
-(IBAction)button1
{
[input resignFirstResponder];
l11 = input.text;
line11.text = [[NSString alloc] initWithFormat:#"%2.f", l11];
}
but I though that it would help if I included my .h file, also.
#import <UIKit/UIKit.h>
#interface QRscannerSecondViewController : UIViewController
#end
#interface TextGameViewController : UIViewController
{
IBOutlet UITextField *input;
IBOutlet UILabel *line11;
NSString *l11;
}
-(IBAction)button1;
You need to put the code:
-(IBAction)button1
{
[input resignFirstResponder];
l11 = input.text;
line11.text = [[NSString alloc] initWithFormat:#"%2.f", l11];
}
before the #end.

TabBarController didSelectViewController not working

I know this is a very repeat topic, but I can't get it works.
MainTab.h:
#import <UIKit/UIKit.h>
#interface MainTab : UITabBarController<UITabBarControllerDelegate, UITabBarDelegate> {
IBOutlet UITabBarController *tabController;
}
#property (nonatomic,retain) IBOutlet UITabBarController *tabController;
#end
MainTab.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
NSLog(#"main tab");
[super viewDidLoad];
self.tabBarController.delegate = (id)self;
[self setDelegate:self];
// Do any additional setup after loading the view.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
NSLog(#"selected %d",tabBarController.selectedIndex);
}
I can't find what I'm missing, any help will be appreciated.
Now I try to link it into MainStoryBoard:
But it doesnt work, what are the connection?
On the basis of your #interface (and your subsequent screen snapshot), MainTab is the UITabBarController, so the following line:
self.tabBarController.delegate = (id)self;
Should just be:
self.delegate = self;
You don't want a tabBarController property in the UITabBarController, itself, nor do you want to use the self.tabBarController syntax. You only use that syntax if you're trying to reference the tab bar controller from one of its children controllers. When in the tab bar controller itself, just refer to self.
Thus, it work if MainBar is defined as:
// MainBar.h
#import <UIKit/UIKit.h>
#interface MainBar : UITabBarController
#end
And
// MainBar.m
#import "MainBar.h"
#interface MainBar () <UITabBarControllerDelegate>
#end
#implementation MainBar
- (void)viewDidLoad
{
[super viewDidLoad];
self.delegate = self;
}
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
NSLog(#"selected %d",tabBarController.selectedIndex);
}
#end
And don't forget to set the class of the tab bar controller:
The connections inspector (where I didn't touch a thing) looks like:

Passing data from controllerA to controllerB using delegate

I am trying to send simple data from viewControllerA to viewControllerB using delegate but can not find The problem in my code.here is the code
in ViewControllerA.h
#import <UIKit/UIKit.h>
#class ViewControllerA;
#protocol viewControllerADelegate <NSObject>
-(void) addItem: (ViewControllerA *)controller data:(NSString *)item;
#end
#interface ViewControllerA : UIViewController
- (IBAction)buttonPressed:(id)sender;
#property (assign) id<viewControllerADelegate> delegate;
#end
inViewControllerA.m
#import "ViewControllerA.h"
#interface ViewControllerA ()
#end
#implementation ViewControllerA
#synthesize delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)buttonPressed:(id)sender {
[self.delegate addItem:self data:#"this is data"];
}
#end
and here is ViewControllerB.h
#import <UIKit/UIKit.h>
#import "ViewControllerA.h"
#interface ViewControllerB : UIViewController<viewControllerADelegate>
#end
and ViewControllerB.m
#import "ViewControllerB.h"
#import "ViewControllerA.h"
#interface ViewControllerB ()
#end
#implementation ViewControllerB
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
ViewControllerA *vba = [[ViewControllerA alloc]init];
[vba setDelegate:self];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void) addItem: (ViewControllerA *)controller data:(NSString *)item{
NSLog(#"delegate function called");
}
#end
The implemented function -(void) addItem: (ViewControllerA *)controller data:(NSString *)item is never called.Am I missing something ? Thanks in advance
Are you using storyboards? If yes, you just push the wrong button: storyboard initializes view controllers on its own, so yours code:
ViewControllerA *vba = [[ViewControllerA alloc]init];
[vba setDelegate:self];
just setting delegate on some unused view controller.
Use segues, don't try to reinvent a wheel.

MySecondViewController won't display correctly

I have programmatically created a second view controller (MySecondViewController) which was all done and hooked up without using the visual object editor.
My problem is that when I run the app, only the original view controller (HelloWorldViewController) comes up; the second view controller does not show up. When I click on the view for HelloWorldViewController, nothing comes up.
Can you tell me what's wrong?
windowBasedAppAppDelegate.h
#import <UIKit/UIKit.h>
//-- Add a forward reference to the HelloWorldViewController class --
#class HelloWorldViewController;
#interface windowBasedAppAppDelegate : NSObject <UIApplicationDelegate> {
//-- create an instance of the view controller--
HelloWorldViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
//--Expose the view controller as a property--
#property (nonatomic, retain) IBOutlet HelloWorldViewController *viewController;
#end
windowBasedAppAppDelegate.m
#import "windowBasedAppAppDelegate.h"
#import "HelloWorldViewController.h"
#import "MySecondViewController.h"
#implementation windowBasedAppAppDelegate
#synthesize window;
#synthesize viewController;
//-- a second view controller object--
MySecondViewController *mySecondViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//-- add the new view to the current window--
//-- instantiate the second view controller --
mySecondViewController = [[MySecondViewController alloc]
initWithNibName:nil
bundle:nil];
// -- add the view from the second controller --
//[window addSubview:mySecondViewController.view];
[window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
[MySecondViewController release];
[viewController release];
[window release];
[super dealloc];
}
#end
MySecondViewController.h
#import <UIKit/UIKit.h>
#interface MySecondViewController : UIViewController {
//-- create two outlets, label and button --
UILabel *label;
UIButton *button;
}
//-- expose the outlets as properties --
#property (nonatomic, retain) UILabel *label;
#property (nonatomic, retain) UIButton *button;
// -- declaring the IBAction ---
- (IBAction) buttonClicked: (id)sender;
#end
MySecondViewController.h
#import "MySecondViewController.h"
#implementation MySecondViewController
#synthesize label, button;
- (IBAction) buttonClicked: (id)sender {
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:#"Action Invoked!" message:#"Button clicked" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
HelloWorldViewController.h
#import <UIKit/UIKit.h>
#interface HelloWorldViewController : UIViewController {
}
#end
HelloWorldViewController.m
import "HelloWorldViewController.h"
#implementation HelloWorldViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
Added code from MySecondViewController.m
//-- add the views to the view window --
[self.view addSubview:label];
[self.view addSubview:button];
[view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
self.view = view;
[super viewDidLoad];
Since the view is being initialized and that it has a proper frame, the problem could be this sequence of code,
[window addSubview:mySecondViewController.view];
[window addSubview:viewController.view];
As the viewController's view will have the same frame, it will be added over mySecondViewController's view. So you will have to remove the second line for the view to show up.
You never actually push the new view controller onto the screen.
mySecondViewController = [[MySecondViewController alloc]
initWithNibName:nil
bundle:nil];
// -- add the view from the second controller --
//[window addSubview:mySecondViewController.view];
[window addSubview:viewController.view];
You add viewController.view, (which should be undefined...), but not mySecondViewController.view.
Also, programHasFinishedLaunching may not be the best possible place to push it. If I were you, I'd put a button on the front page that pushes the new view in, it's easier that way.