unable to detect UITextField - ios

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

Related

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.

Connecting IBOutlet to UITextView makes UITextView invisible

I have checked thoroughly for a solution to this (notably here: Can't connect IBOutlet in Interface Builder) but cannot see the solution. I have a UITextView that I am using as a text area in a form. I have connected it to this class member in IB:
IBOutlet UITextView *notes;
here is my .h
#import <UIKit/UIKit.h>
#import <AddressBookUI/AddressBookUI.h>
#interface U2MIDetailController : UIViewController <UITextFieldDelegate, UITextViewDelegate> {
IBOutlet UIButton *confirmButton;
IBOutlet UITextView *notes;
}
#property (nonatomic, retain) IBOutlet UITextView* notes;
#property ABRecordRef personObject;
#property (strong, nonatomic) IBOutlet UIScrollView *scroller;
#end
and my .m, the relevant bits:
#synthesize notes;
- (void)viewDidLoad
{
[super viewDidLoad];
//set up delegates for keyboard hiding
notes.delegate = self;
notes.text = #"Notes";
...
}
In the links I've found some have solved this issue by checking the File's Owner "Class" attribute on the Identity inspector. How do I do that? I have attached a pic of the hierarchy which looks correct to me, the identity inspector doesn't jump out at me either as having any suspicious properties.
Here is a shot of the storyboard:
and here is how it looks int he simulator:
check your scrollview frame either it is fit to frame or not. put blackground color you know where you did mistake

Access an IBOutlet from another class?

I need to access this IBOutlet's value in another class.. How would I go about doing this?
Heres my SaveTextViewController.h class
#import <UIKit/UIKit.h>
#interface SaveTextViewController : UIViewController{
IBOutlet UITextField *saveText;
}
#property (retain, nonatomic) IBOutlet UITextField *saveText;
#end
And here is my TextView.m class
#import "TextView.h"
#import "SaveTextViewController.h"
#implementation TextView
- (IBAction)saveTextView{
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
//Trying to access the returned variable "saveText" from IBOutlet in SaveTextViewController
NSString *documentTXTPath = [documentsDirectory stringByAppendingPathComponent:#"%d",saveText];
NSString *savedString = self.text;
[savedString writeToFile:documentTXTPath atomically:YES];
NSLog(#"%#", documentTXTPath);
}
Thanks!
There is no clean way to just generically access the IBOutlet UITextField *saveText from any app. You can declare it in the .h file instead of the .m and have it accessible that way, assuming you can send a pointer to your SaveTextViewController class. But its a better practice to pass a pointer to your UITextFIeld to your TextView class from your SaveTextController class.
in TextView.h create a property
#interface TextView: UIView
#property (nonatomic, strong) UITextField *textField;
#end
in your SaveTextViewController.m create another property:
#interface SaveTextViewController : UIViewController{
IBOutlet UITextField *saveText;
}
#property (retain, nonatomic) TextView *textView;
#property (retain, nonatomic) IBOutlet UITextField *saveText;
assign self.textView to your TextView
in your viewDidLoad method, set the textField in your TextView class like this:
self.textView.textField = self.saveText;
That would give you a clean connection between those two classes.
An IBOutlet is just behaving like any other property or instance variable. So if you want to pass that reference to another class, just do exactly that. Note that you do not need to specify an instance variable with the same name as the property. The current runtime will handle this itself.
If you want to pass a reference to the UITextField, add a property to your text view.
#interface TextView : UIView
#property (retain, nonatomic) UITextField *saveTextField;
...
#end
In your SaveTextViewController you can now set that property. You can do this in the viewWillAppear: method for example.
#implementation SaveTextViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.textView.saveTextField = self.saveText
}
#end
Also note that if you need a reference to the TextView and you created that in your nib/storyboard, add another IBOutlet to the SaveTextViewController.
#import "TextView.h"
#interface SaveTextViewController : UIViewController
#property (retain, nonatomic) IBOutlet UITextField *saveText;
#property (retain, nonatomic) IBOutlet TextView *textView;
#end
Finally I would also recommend you to rename saveText to saveTextField, because that's what it is. Also, you seem to be using unsanitized user input data from text fields and feed them into filenames. This is generally a bad idea™. I would recommend you to think about what you are actually trying to do. This is potentially dangerous and can lead to data loss and more fun stuff.
In
#implementation TextView
type
SaveTextViewController *saveTextViewController = [[SaveTextViewController alloc] init];
NSString *documentTXTPath = [documentsDirectory stringByAppendingPathComponent:#"%d",saveTextViewController.saveText];
Hope this helps!

Warning in #property (nonatomic,retain) UISegmentedControl *colorChooser;

I have created one segmented control and a text view in my .xib file and I have declare it in .h file as
#interface controlsViewController : UIViewController {
IBOutlet UISegmentedControl *colorChooser;
IBOutlet UITextView *setText;
}
#property (nonatomic,retain) UISegmentedControl *colorChooser;
#property (nonatomic,retain) UITextView *setText
but it shows me warning on both lines of #property
Can anyone tell me why it warns me?
My guess would be that you don't have a #synthesize or #dynamic in your implementation. That would generate compiler warnings.
The position of the IBOutlet wound not generate a compiler warning as it's a marco of nothing. It's used by xcode resource editor (or the older Interface Builder) to indicate it's a outlet property and doesn't generate any code.
#interface controlsViewController : UIViewController {
UISegmentedControl *colorChooser;
UITextView *setText;
}
#property (nonatomic,retain) IBOutlet UISegmentedControl *colorChooser;
#property (nonatomic,retain) IBOutlet UITextView *setText;
You need to synthesize the property in your .m file. You won't get the error then.

Resources