I can't figure how to fix this Expected identifier or '(' - ios

- (IBAction)SignUp:(id)sender; { Expected identifier or '('
IBOutlet UITextField *Firstnamefield;
IBOutlet UITextField *Lastnamefield;
IBOutlet UITextField *emailfield;
IBOutlet UITextField *agefield;
IBOutlet UITextField *passwordfield:
IBOutlet UITextField *reenterpasswordfield;
}

- (IBAction)SignUp:(id)sender {
UITextField *Firstnamefield;
UITextField *Lastnamefield;
UITextField *emailfield;
UITextField *agefield;
UITextField *passwordfield;
UITextField *reenterpasswordfield;
}
There a couple of problems. For one, you can not use the IBOutlet qualifier outside of an interface declaration. And passwordfield has a colon after it that should be a semicolon.
In case this is the point of confusion, if you were creating the interface declaration for this IBAction, it would look like this:
- (IBAction)SignUp:(id)sender;
Other than that, the only other thing that could be causing this is if you are trying to place the entire IBAction inside the header file.

It seems to me that you put an IBAction at the wrong place in the .h file.
It should be after the definition of the instance variables, for example:
#interface ViewController : UIViewController
{
IBOutlet UITextField *Firstnamefield;
IBOutlet UITextField *Lastnamefield;
// ...
}
- (IBAction)SignUp:(id)sender;
#end

Related

Set UILabel text using KVC

How to set UILabel text using KVC in iOS ?
Suppose I have following lines of code :
#property (nonatomic, strong) UILabel *nameLabel;
[self setValue:#"someName" forKeyPath:#"nameLabel.text"];
NSLog(#"Using KVC :Output name label - %#",[self valueForKeyPath:#"nameLabel.text"]);
/* Returns nil */
#property (weak, nonatomic) IBOutlet UILabel *nameLabel;
[self setValue:#"Testing123" forKeyPath:#"nameLabel.text"];
See the image below of the storyboard
Seem like I found the fix. UILabel must be on subview, either by dragging and dropping on the storyboard and creating IBOutet or by programatically adding it on the subview.
So, #property (nonatomic, weak) IBOutlet UILabel *nameLabel; did the trick for me.

Xcode 4 storyboard, textfields not wanting to connect to IBOutlet

So in the storyboard i have a UIViewController class called FormViewController. I set the ViewController in the storyboard to use that:
I then have the three text fields in the header file:
#import <UIKit/UIKit.h>
#interface FormViewController : UIViewController
#property (strong, retain) IBOutlet UITextView *firstName;
#property (strong, retain) IBOutlet UITextView *lastName;
#property (strong, retain) IBOutlet UITextView *email;
- (IBAction) save:(id)sender;
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;
#end
However, when i try to connect the ones in the storyboard to the view controller, it doesnt pop up.
Any ideas?
UITextField and UITextView are two very different classes—you have created UITextField instances but your outlets are typed as UITextView.
Just change your outlet types to UITextField and all should be well!
(UITextView, for the record, is a scrolling, often editable field, more like a word processor.)

Custom UIView with UILabel iOS

I have a UIView with two UILabel that I want to reuse in more than one UIViewController. I use storyboard and I assign a custom class alertView:UIView that I declared.
file AlertRemote.h
#interface AlertRemote: UIView
#property (weak, nonatomic) IBOutlet UILabel *label1;
#property (weak, nonatomic) IBOutlet UILabel *label2;
-(void) setTextLabel;
file AlertRemote.m
-(void) setTextLabel{
[ _label1 setText:#"attention..."];
[_label2 setText:#"the program..."];
}
file Controllo.m
//the view present in the storyboard alertView linked to the uiview
#property (strong, nonatomic)IBOutlet AlertRemote *alertView;
#property AlertRemote *alRemView;
[super viewDidLoad];
_alertView=_alRemView; [_alertView setTextLabel];
[_alertView setTextLabel];
if I put some breakpoints inside setTextLabel the code don't works
thanks!!
In order for the custom alert to work, you need to initialise it.
AlertRemote *alRemView;
alRemView = [[AlertRemote alloc]init];
[alRemView setTextLabel];
I think you are not initializing the property alertview. If you are initializing the property alertview then try to set directly with out using alremView.

unable to detect UITextField

Hey guys I am unable to find or connect my UITextField loginId with my custom viewcontroller.h file. when I try to get that class using NSString *data = loginId.text;it tells me that it is non existant.
.h file:
#import <UIKit/UIKit.h>
UITextField *loginId;
UITextField *password;
#interface loginController : UIViewController
- (IBAction) loginBegin:(id) sender;
#end
.m file:
NSString *intakePass = loginId.text;
I tried cleaning my project but that seems not to work. I notice that when I go to the storyboard to add in a custom class usually the classname I make in the .h file will drop down but nothing comes up. But it is set to loginId.
Suggestions, thoughts?
IBOutlet is the Key to Make them visible in XIB. So u must specify them as IBOutlet.
You must drag UITextField from library, not other components.Please verify it on XIB that you are connecting Text Field and make sure the class name of text field. it should be UITextField or UITextField Subclass.
#interface loginController : UIViewController{
IBOutlet UITextField *loginId;
  IBOutlet UITextField *password;
}
#property(weak,nonatomic) IBOutlet UITextField *loginId;
#property(weak,nonatomic) IBOutlet UITextField *password;
- (IBAction) loginBegin:(id) sender;
#end
Apple Documentation says
IBOutlet your UITextField as below in your .m file:
#interface ViewController ()
#property(weak,nonatomic) IBOutlet UITextField *loginId;
#property(weak,nonatomic) IBOutlet UITextField *password;
#end
now you can connect your textfile in xib

Changing outlet object properties

I have a view controller alertForNeedsClassification as a property in another class, as such:
#interface SCAAppDelegate()
{
HomeScreenViewController * _homeScreenViewController;
NSInteger SCAStatus;
}
#property (strong, nonatomic) PromptClassifyViewController * alertForNeedsClassification;
#end
#implementation SCAAppDelegate
#synthesize alertForNeedsClassification;
#synthesize window = _window;
PromptClassifyViewController's interface looks like this:
#interface PromptClassifyViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *headerTitle;
#property (weak, nonatomic) IBOutlet UITextView *message;
#property (weak, nonatomic) IBOutlet UIButton *notNowButton;
#property (weak, nonatomic) IBOutlet UIButton *classifyButton;
#property (weak, nonatomic) IBOutlet UIImageView *backgroundImageView;
#property (weak, nonatomic) IBOutlet UIView *alertView;
#property NSUInteger tag;
#property (weak, nonatomic) IBOutlet id<PromptClassifyViewControllerDelegate> delegate;
- (void)show;
- (void)showFromView:(UIView *)view;
- (IBAction)show:(id)sender;
- (IBAction)dismiss:(id)sender;
- (IBAction)buttonWasPressed:(id)sender;
- (void)setHeaderTitleWithText:(NSString *)text;
#end
I am trying to change the values of IBOutlets message and headerTitle text, like this:
alertForNeedsClassification = [[PromptClassifyViewController alloc] initWithNibName:#"PromptClassifyViewController" bundle:nil];
//[alertForNeedsClassification setDelegate:self];
self.alertForNeedsClassification.headerTitle.text = #"A title";
alertForNeedsClassification.message.text = #"A message";
Then I show alertForNeedsClassification calling a show method (it's like a custom uialertview, but it doesn't subclass from uialertview).
Thing is, no matter how I change it, the text on alertForNeedsClassification.view is always that which is defined in the nib, ie. I can't change it programmatically.
My custom alert view is based on Jeff LaMarche's design: http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html
Any ideas what might be going on?
Please be careful when you allocate and initialize the UIView object, especially if you trying to mix using Nib and dynamically generating objects. The best place is within -(void)awakeFromNib or -(void)viewDidLoad
Also, make sure these methods are called. By using -(id)initWithNibName:bundle: only cannot make sure your view to be loaded. Try -(void)addChildViewController and -(void)addSubview: on parentViewController's view to make sure view is loaded after being initialized.
If the text had to be prepared before being loaded, assign it to separate NSString property within PromptClassifyViewController class. Since this property is independent from view being loaded, you can change it's value BEFORE view is appeared. Make sure this text is used and applied to the headerTitle within -(void)show method.
Since you allocate PromptClassifyViewController and access weak referenced headerTitle from self. alertForNeedsClassification, make sure it's not deallocated right afterward.
Usually, weak option is not used for IBOutlet properties. Though it is used when generating outlet connection code by dragging objects from Interface Builder. Try testing your code using strong.
I was assigning values to the IBOutlets before they were alloc'd/initialized. The solution I implemented was to set the values I needed to non-IBOutlet properties (NSStrings in this case) and assign those where needed, in Prompt...Controller's viewDidLoad;

Resources