CHAPTER 3 EXERCISE SOLUTIONS

Answer to Question 1

In the .h file:

#import <UIKit/UIKit.h>

@interface OutletsAndActionsViewController : UlViewController
{
    //---declaring the outlet---
    IBOutlet UITextField *txtName;
}

//---expose the outlet as a property---
@property (nonatomic, retain) UITextField *txtName;

@end

In the .m file:

#import “OutletsAndActionsViewController.h”

@implementation OutletsAndActionsViewController

//---synthesize the property---
@synthesize txtName;

- (void)dealloc {
    //---release the outlet---
    [txtName release];
    [super dealloc];
}

Answer to Question 2

In the .h file:

#import <UIKit/UIKit.h>

@interface OutletsAndActionsViewController : UIViewController
{
    //---declaring the outlet---
    IBOutlet UITextField *txtName;
}

//---expose the outlet as a property---
@property (nonatomic, retain) UITextField *txtName;

//---declaring the action---
-(IBAction) btnClicked:(id) sender;

@end

In the .m file:

@implementation OutletsAndActionsViewController

-(IBAction) btnClicked:(id) sender {
     //---action implementation here---
}

Answer to Question 3

Use the alert view when you simply want to notify the user when something happens. Use an action sheet when the user needs to make a selection, usually from a set of options.

Answer to Question 4

//---create a Button view---
frame = CGRectMake(10, 70, 300, 50);
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = frame;
[button setTitle:@“Click Me, Please!” forState:UIControlStateNormal];
button.backgroundColor = [UIColor clearColor];
button.tag = 2000;
[button addTarget:self
           action:@selector(buttonClicked:)
 forControlEvents:UIControlEventTouchUpInside];
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.238.141