How to get value of textfield in AppDelegate in Xcode - xcode

I have 2 textfields in a view. I want to read value of this fields in AppDelagate.m.
It is very strange that does not work me all methods.
I posted my code here:
in First View
#property (nonatomic, retain) IBOutlet UITextField *Usernametxtbx;
#property (nonatomic, retain) IBOutlet UITextField *Passwordtxtbx;
Can you help me?

Its very odd that you need to read the values of outlets in an AppDelegate. AppDelegate is to handle your app delegate methods such as when your app launches or when your app is supposed to enter background. In didFinishLaunchingWithOptions, the outlets will be nil. You should be doing these tasks in viewDidLoad.

Related

UIButton and UILabel not showing up on device screen

I have a UILabel and UIButton in my Xib interface builder. The 600x600 screen says what I'll dragging+dropping on is a View.
When I drag and drop the label and button onto the view, and make them IBOutlet properties, they seem to not be part of any view hierarchy.
#property (retain, nonatomic) IBOutlet UILabel *label;
#property (retain, nonatomic) IBOutlet UIButton *button;
They each have their own respective constraints.
Here's two images.
Interface Builder
Interface Builder Outlet
I have synthesized both properties. Do I need to do anything programmatically? I thought Interface builder took care of everything, which is why I ask. The class in question is a custom subclass of a UIViewController, so do I need to drag and drop on to a view controller instead?

How does apple set the Delegates of the UIKit classes as Outlets?

I've been trying to find a way to set the delegates on my custom classes as Outlets so I can connect them via IB just like one does with an UIKit Class but I haven't been able to do this, is this even possible?
Yes you will need to the IBOutlet keyword to the delegate property.
Like:
#property (nonatomic, assign) IBOutlet id <YourDelegateClass> delegate;

UITextView not editable

I am very confused by the following - I realise a difficult question to answer but ...
I have a number of UITextViews all set up in exactly the same way. Other than their name and position on the screen they are all identical. All settings are exactly the same in the File Inspector. They are established in the same way:
#property (weak, nonatomic) IBOutlet UITextView *timeStamps;
#property (weak, nonatomic) IBOutlet UITextView *slider1Comments;
When a button is pressed they are activated.
timeStamps.editable=YES;
[timeStamps setUserInteractionEnabled:YES];
slider1Comments.editable=YES;
[slider1Comments setUserInteractionEnabled:YES];
However, when I press the button I am not able to enter anything into timeStamps while I can in slider1Comments.
I have just upgraded to Xcode 5 and noticed a number of changes - maybe it is related. Any ideas?
try doing this
uncheck the "editable" and "user interaction enabled" for both the uitext views and set the delegates for both textviews in interface builder
hope it helps..

Xcode UIImageView won't link to the code

I have a problem:
I need to insert a UIImageView into my application that changes images each time. The code I have written is correct, but the UIImageView box I dragged on my view in storyboard won't link to the code. I drag the blue line on the codes but it just does not link.
#property (nonatomic, retain) IBOutlet UIImageView *image1
Can you help me????
Two possible things:
are you also adding it in your #Interface in the .h file? like below:
#interface FirstViewController : UIViewController {
IBOutlet UIImageView *image1;
}
Also, after you do this make sure you are linking your UIImage View to your files owner in the .xib file. control drag from "File's Owner" right into the image view.
I don't have a ton of iOS experience, but these are two pretty common problems.
h file
#property (nonatomic, retain) IBOutlet UIImageView *image1
m file
#synthesize image1;
Link should show up.

Question about NSWindowController and NSPersistentDocument Core Data Tutorial

In the Implementation Overview section of the NSPersistentDocument Core Data Tutorial it says:
…
One issue with creating the new top-level object in the nib file is that when you use bindings an object retains other objects to which it is bound. This means that bindings must be broken to ensure there are no retain cycles when a document is closed. Moreover, since the nib file the new controller owns contains top level objects and the controller’s class does not inherit from NSWindowController, you need to release the top level objects when the window is closed.
Why not just have the controller inherit from NSWindowController? Is there a reason this would not work? Or was this just a matter of style?
As commented below, I did get this to work with an NSWindowController subclass, and it does seem to save quite a bit of code.
Here is my subclass header:
#import <Cocoa/Cocoa.h>
#interface NewAccountSheetController : NSWindowController {
#private
BOOL isValidForInsert;
NSManagedObjectContext * managedObjectContext;
NSObjectController * objectController;
NSObjectController * targetController;
}
#property (setter=setValidForInsert:) BOOL isValidForInsert;
#property (nonatomic, retain) IBOutlet NSManagedObjectContext * managedObjectContext;
#property (nonatomic, retain) IBOutlet NSObjectController * objectController;
#property (nonatomic, retain) IBOutlet NSObjectController * targetController;
- (void)beginSheetForWindow:(NSWindow *)window;
- (IBAction)endSheet:(id)sender;
#end
And here is the implementation in a Pastebin.
I have no good idea how to describe the required bindings, etc. but if you're familiar with the above tutorial they should be straightforward to extrapolate… I think. :-)
In the example, its talking about controlling a sheet instead of a window. A sheet is technically a window component and not a window itself so it can't use a NSWindowController subclass as a controller. A window controller does not know how to handle a window owned by another window.
The text above is just reminding you that although the sheet controller looks very much like a window controller it is not one and that you have to manually handle releasing that is handled automatically by the window controller.

Resources