Hopefully you're not actually putting code into main. M On iOS, you rarely modify that file Since you're doing everything in the AppDelegate, let's keep it there (as opposed to creating a new UIViewController ). Let's start with the basics Adding the Label as an instance variable You're doing this correctly—inside the curly braces of the h file, put the line IBOutlet UILabel * questionField Then, declare the corresponding property, and make sure to synthesize it in the m file property (nonatomic, retain) IBOutlet UILabel *questionField; @synthesize questionField // in the .
M file Adding the UILabel in Interface Builder Open up MainWindow. Xib Drag a UILabel from the Library to the Window that represents your app's window. Then Control-Drag from the AppDelegate object (the third icon on the left in Xcode 4; it'll be labelled in the Document window in IB 3).
You'll see a little black window come up—select the option called questionField to make the connection See this link for screenshots and how to make connections in IB. The same applies in Xcode 4 Changing the text You don't need a separate method to change the text—just modify the label's text property Pick a method that'll be called when the app launches ( applicationDidFinishLaunching:WithOptions: is a good place to do it in), and put the following code: questionField. Text = @"Code QuizAppDelegate.
H import @interface QuizAppDelegate : NSObject { IBOutlet UILabel *questionField; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UILabel *questionField; @end QuizAppDelegate. M import "QuizAppDelegate. H" @implementation QuizAppDelegate @synthesize window=_window; @synthesize questionField; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch.
// Add the tab bar controller's current view as a subview of the window self. Window addSubview:self. QuestionField; self.
Window makeKeyAndVisible; self.questionField. Text = @" } - (void)dealloc { _window release; questionField release; super dealloc; } @end.
Hopefully you're not actually putting code into main.m. On iOS, you rarely modify that file. Since you're doing everything in the AppDelegate, let's keep it there (as opposed to creating a new UIViewController).
Let's start with the basics. Adding the Label as an instance variable You're doing this correctly—inside the curly braces of the . H file, put the line IBOutlet UILabel * questionField; Then, declare the corresponding property, and make sure to synthesize it in the .
M file. @property (nonatomic, retain) IBOutlet UILabel *questionField; @synthesize questionField // in the . M file Adding the UILabel in Interface Builder Open up MainWindow.xib.
Drag a UILabel from the Library to the Window that represents your app's window. Then Control-Drag from the AppDelegate object (the third icon on the left in Xcode 4; it'll be labelled in the Document window in IB 3). You'll see a little black window come up—select the option called questionField to make the connection.
See this link for screenshots and how to make connections in IB. The same applies in Xcode 4. Changing the text You don't need a separate method to change the text—just modify the label's text property.
Pick a method that'll be called when the app launches (applicationDidFinishLaunching:WithOptions: is a good place to do it in), and put the following code: questionField. Text = @" Code QuizAppDelegate. H #import @interface QuizAppDelegate : NSObject { IBOutlet UILabel *questionField; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UILabel *questionField; @end QuizAppDelegate.
M #import "QuizAppDelegate. H" @implementation QuizAppDelegate @synthesize window=_window; @synthesize questionField; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // Add the tab bar controller's current view as a subview of the window self.
Window addSubview:self. QuestionField; self. Window makeKeyAndVisible; self.questionField.
Text = @" } - (void)dealloc { _window release; questionField release; super dealloc; } @end.
If you were to create a new UIViewController subclass, go for the View-Based Application template. Then declare the ivar and property in the . H and put self.questionField.
Text = @"hello"; in the viewDidLoad method. Make sure to release the label in dealloc if you're retaining it—which you should. – Inspire48 Jun 10 at 21:25 Thank you so much.It worked perfectly.
:D – Anders Jun 10 at 21:40 Out of curiosity, what were you doing wrong? – Inspire48 Jun 10 at 21:48 I think didFinishLaunchingWithOptions was the secret sauce. Would have taken a long time to figure that out.
So thanks! – Anders Jun 10 at 22:02 No prob! Glad to help.
– Inspire48 Jun 10 at 22:07.
If you're creating the label programmatically, then you have to add the label to the view: self. View addSubview:questionField; This assumes that you have a ViewController. If not, and you're doing this directly in the AppDelegate (a very bad idea, by the way), then do self.
Window addSubview:questionField; If you're creating it in the IB, make sure you set up the connections. You should not both add the UILabel in the IB and instantiate it programmatically. Only call alloc if you are creating it programmatically.
Otherwise, if using the IB, skip that part. You created it already with the xib.
...but this: IBOutlet UILabel * questionField; implies the view is built using IB. – Roger Nolan Jun 10 at 21:05 Implies, perhaps, but only if the programmer really means that. – PengOne Jun 10 at 21:07 Thanks for your answer.
I got the following error by putting this in my . M file: QuizAppDelegate. M: error: Semantic Issue: Property 'view' not found on object of type 'QuizAppDelegate *'.
Yes, I have used interface builder. – Anders Jun 10 at 21:13 Set up a ViewController or else add the view to the window. – PengOne Jun 10 at 21:14.
I suspect that you have either not created your Interface Builder layout properly - either you have missed the control out all together or more likely you have not connected that control to the questionField outlet in yout header file. You need to drag a UILabel view into the main view and then connect it to the correct line in your header file.
I have (cntrl) dragged from the UILabel to IBOutlet UILabel * questionField; And I have imported in my header file. I have a coupe of other classes, do I need there as well? – Anders Jun 10 at 21:16.
You shouldn't be using your main. M like that at all. In fact, you should almost certainly never do anything with it.
Try creating a UIViewController subclass and practicing your quiz with that. (Add the UILabel to the IB file and then connect the outlet. ) Perhaps use the View-Based Application template while you are practicing.
UIViewController is a good option, but for beginners working with just a Window-Based Application is also a good option. – Inspire48 Jun 10 at 21:23.
Drag a UILabel from the Library to the Window that represents your app's window. Then Control-Drag from the AppDelegate object (the third icon on the left in Xcode 4; it'll be labelled in the Document window in IB 3). You'll see a little black window come up—select the option called questionField to make the connection.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.