Expected specifier-qualifier-list - Why? - objective-c

I've got an app I'm working on, its got 4 views so far that work fine, I've added another view (with .h & .m files) and now it wont compile. I've copied the code from the other lines but cannot figure out the problem.
the error is on line IBOutlet fifthViewController *fifthViewController;
#import <UIKit/UIKit.h>
#class FirstViewController;
#class SecondViewController;
#class ThirdViewController;
#class ForthViewController;
#class fifthviewcontroller;
#interface MulipleViewsViewController : UIViewController {
IBOutlet FirstViewController *firstViewController;
IBOutlet SecondViewController *secondViewController;
IBOutlet ThirdViewController *thirdViewController;
IBOutlet ForthViewController *forthViewController;
IBOutlet fifthViewController *fifthViewController;
}
#property (retain, nonatomic) FirstViewController *firstViewController;
#property (retain, nonatomic) SecondViewController *secondViewController;
#property (retain, nonatomic) ThirdViewController *thirdViewController;
#property (retain, nonatomic) ForthViewController *forthViewController;
#property (retain, nonatomic) fifthviewcontroller *FifthViewController;
-(IBAction) loadSecondView:(id)sender;
-(IBAction) loadThirdView:(id)sender;
-(IBAction) loadFirstView:(id)sender;
-(IBAction) loadForthView:(id)sender;
-(IBAction) loadFifthView:(id)sender;
-(void) clearView;
#end

I think the problem is here:
#property (retain, nonatomic) fifthviewcontroller *FifthViewController;
it should be:
#property (retain, nonatomic) Fifthviewcontroller *fifthViewController;
and of course
IBOutlet fifthViewController *fifthViewController;
should be:
IBOutlet FifthViewController *fifthViewController;
here too:
#class fifthviewcontroller;
should be
#class FifthViewcontroller;

When you declare the class and property, you use fifthviewcontroller with no capitals, but when you declare the instance variable, you capitalize the V and C: fifthViewController. From the context, it appears that the capitalizations are a mistake and that line should be changed to IBOutlet fifthviewcontroller *fifthViewController;
In the future, when posting about errors, please indicate in the code which line the error occurs on.

Related

Changing label's data using textField inout

I want to change the label's text (which is embedded in a tableViewCell) using a textField data (which is embedded outside the tableViewCell).
Can anyone share the code please using objective-C.
Here is my TableViewCell.h file.
#import <UIKit/UIKit.h>
#interface TableViewCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UILabel *label1;
#property (strong, nonatomic) IBOutlet UILabel *label2;
#end
Here is my storyboard controller file
#import <UIKit/UIKit.h>
#interface ViewController:UIViewController<UITableViewDelegate,UITableViewDataSource>
{
NSMutableArray *contacts;
}
- (IBAction)leftBtn:(id)sender;
- (IBAction)rightBtn:(id)sender;
- (IBAction)nextBtn:(id)sender;
- (IBAction)SendBtn:(id)sender;
#property (strong, nonatomic) IBOutlet UITableView *tabV1;
#property (strong, nonatomic) IBOutlet UITextField *txtField;
#end
Here I have the button action connection where I should I write the actual code to change the label's data using a text field.
- (IBAction)leftBtn:(id)sender {
}

How can I improve my attempt to create protected properties

#import "BGReviewController.h"
#interface BGReviewController (protected)
#property (weak, nonatomic) IBOutlet UIImageView *backgroundImage;
#property (weak, nonatomic) IBOutlet UIButton *dislikeButton;
#property (weak, nonatomic) IBOutlet UIButton *likeButton;
#property (weak, nonatomic) IBOutlet UIButton *post;
#property (weak, nonatomic) IBOutlet UIButton *cancel;
#property (weak, nonatomic) IBOutlet UITextView *textView;
#end
Then I add:
#synthesize backgroundImage = _backgroundImage;
#synthesize dislikeButton = _dislikeButton;
#synthesize likeButton = _likeButton;
#synthesize post = _post;
#synthesize cancel = _cancel;
#synthesize textView = _textView;
And I got error:
/business/Dropbox/badgers/BadgerNew/BGReviewController.m:32:13: Property declared in category 'protected' cannot be implemented in class implementation
Should I declare the synthesize in the implementation file of the category and then put the ivars explicitly?
you cant #synthesize in a category, you have to do the getters and setter manually
check out this answer
Replace
#interface BGReviewController (protected)
With
#interface BGReviewController ()

Textfield return (null) no matter what

I have searched stackoverflow for similar problems and have found some, but they did not resolve my problem. I have 3 textfields (name,address,phone) from which I want to get the text. I have declared them in the (.h) file, also the #property, and then #synthesized them in the (.m) file. I have a IBAction for a button declared in the (.h) file and linked up correctly. Now when I push this button I want to get the values from the textfields but NSLog shows they are all (null) even before I do anything with the textfields. Its very simple code, i can't understand why it returns null.
//CoreDataViewController.h
#interface coreDataViewController : UIViewController {
UITextField *name;
UITextField *address;
UITextField *phone;
UILabel *status;
}
#property (strong, retain) IBOutlet UITextField *name;
#property (strong, retain) IBOutlet UITextField *address;
#property (strong, retain) IBOutlet UITextField *phone;
#property (strong, retain) IBOutlet UILabel *status;
- (IBAction) saveData;
#end
//CoreDataViewController.m
#import "coreDataViewController.h"
#import "AppDelegate.h"
#implementation coreDataViewController
#synthesize name=_name;
#synthesize phone=_phone;
#synthesize address=_address;
#synthesize status=_status;
- (void) saveData
{
NSLog(#"Name %# Address %# Phone %#",self.name.text,self.address.text,self.phone.text);
...some more code (commented out)....
}
IMO you have incorrectly synthesized iVars.
You use syntax:
synthesize name=_name;
but in the .h file you have:
#interface coreDataViewController : UIViewController {
UITextField *name;
UITextField *address;
UITextField *phone;
UILabel *status;
}
Change this part to:
#interface coreDataViewController : UIViewController {
UITextField *_name;
UITextField *_address;
UITextField *_phone;
UILabel *_status;
}
Just change below code
write synthesize like this
#synthesize name;
#synthesize phone;
#synthesize address;
#synthesize status;
ratherthen
#synthesize name=_name;
#synthesize phone=_phone;
#synthesize address=_address;
#synthesize status=_status;

Expected { before interface

Why am I getting the above compilation error in all of my source files after creating editing this file:
#import <UIKit/UIKit.h>
#protocol FlipsideViewControllerDelegate;
#interface FlipsideViewController : UIViewController {
id <FlipsideViewControllerDelegate> delegate;
UITextField *textField;
}
#property (nonatomic, retain) IBOutlet UITextField *textField;
#property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
#end
#protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
#end
-(IBAction) textChanged:(id) sender;
After editing my flipsidecontroller.h to look like this. I get the error in all of my other source files. Like this one:
// MainViewController.h
// MVC
//
// Created by Nick Martin on 3/31/11.
// Copyright 2011 Nick. All rights reserved.
//
#import "FlipsideViewController.h"
#interface MainViewController : UIViewController <FlipsideViewControllerDelegate> {
UILabel *label;
}
#property (nonatomic, retain) IBOutlet UILabel *label;
- (IBAction)showInfo:(id)sender;
#end
It is complaining about the interface declaration for each of my controllers???
Thanks in advance for the help!
Update - put the textChanged event into the interface
// FlipsideViewController.h
// MVC
//
// Created by Nick Martin on 3/31/11.
// Copyright 2011 Nick Martin. All rights reserved.
//
#import <UIKit/UIKit.h>
#protocol FlipsideViewControllerDelegate;
#interface FlipsideViewController : UIViewController {
id <FlipsideViewControllerDelegate> delegate;
UITextField *textField;
}
#property (nonatomic, retain) IBOutlet UITextField *textField;
#property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
- (IBAction)done:(id)sender;
#end
-(IBAction) textChanged:(id) sender; //DOH!!!
#protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
#end
Your textChanged: method isn't in an interface or protocol. Did you mean to include it in FlipsideViewController or FlipsideViewControllerDelegate?
You have this:
-(IBAction) textChanged:(id) sender;
but it seems to have fallen outside of your #protocol after the #end.

IBOutlet declarations?

I have seen the code below written 3 different ways (with regards to IBOutlet) Does it matter, I would say adding IBOutlet to both the declaration and the #property was more concise.
JUST PROPERTY:
#class SwitchViewController;
#interface iPhone_switcherAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
SwitchViewController *switchViewController;
}
#property(nonatomic, retain) IBOutlet UIWindow *window;
#property(nonatomic, retain) IBOutlet SwitchViewController *switchViewController;
#end
JUST DECLARATION:
#class SwitchViewController;
#interface iPhone_switcherAppDelegate : NSObject <UIApplicationDelegate> {
IBOutlet UIWindow *window;
IBOutlet SwitchViewController *switchViewController;
}
#property(nonatomic, retain) UIWindow *window;
#property(nonatomic, retain) SwitchViewController *switchViewController;
#end
BOTH:
#class SwitchViewController;
#interface iPhone_switcherAppDelegate : NSObject <UIApplicationDelegate> {
IBOutlet UIWindow *window;
IBOutlet SwitchViewController *switchViewController;
}
#property(nonatomic, retain) IBOutlet UIWindow *window;
#property(nonatomic, retain) IBOutlet SwitchViewController *switchViewController;
#end
cheers gary
IBOutlet does only matter to InterfaceBuilder. For the compiler, UINibDeclarations.h #defines it to nothing.
InterfaceBuilder takes IBOutlet as a hint from the header file to list the available outlets for the class. If you wire up an object to an IBOutlet, no matter whether it is defined as a property or instance variable, this information is written into the nib.
When loading the nib, the loader tries to find the best possible way to setup the connection: First it tries to find a setter method with an appropriate name. If no such setter is found, it falls back to setting the instance variable directly, which is poor style, because memory management is not clear this way.
All your proposed examples have a property (and, of course, a setter method) of the right name. So in each case, the loader would use the setter method, no matter where the IBOutlet tag stands: There’s no difference between your examples, neither in the nib, nor in the way code is executed.
The best style would be to put the IBOutlet tag into the property definition.
Should not matter. With the 10.6 64-bit SDK you can also write the property without the ivar:
#class SwitchViewController;
#interface iPhone_switcherAppDelegate : NSObject <UIApplicationDelegate> {
}
#property(nonatomic, retain) IBOutlet UIWindow *window;
#property(nonatomic, retain) IBOutlet SwitchViewController *switchViewController;
#end
The current style in Apple's example code puts the IBOutlet in the property declaration. For consistency, that's probably the best place to throw it.
I also found this way (without any property declaration):
#class SwitchViewController;
#interface iPhone_switcherAppDelegate : NSObject <UIApplicationDelegate> {
IBOutlet UIWindow *window;
IBOutlet SwitchViewController *switchViewController;
}
#end
What about this?