Skip to Content
Beginning iOS 5 Application Development
book

Beginning iOS 5 Application Development

by Wei-Meng Lee
January 2012
Beginner content levelBeginner
655 pages
16h 35m
English
Wrox
Content preview from Beginning iOS 5 Application Development

CHAPTER 4 EXERCISE SOLUTIONS

Answer to Question 1

mySecondViewController = [[MySecondViewController alloc]
                             initWithNibName:@“MySecondViewController”
                                   bundle:nil];

Answer to Question 2

- (void)viewDidLoad {
    //---create a CGRect for the positioning---
    CGRect frame = CGRectMake(20, 10, 280, 50);

    //---create a Label view---
    label = [[[UILabel alloc] initWithFrame:frame] autorelease];
    label.textAlignment = UITextAlignmentCenter;
    label.font = [UIFont fontWithName:@“Verdana” size:20];
    label.text = @“This is a label”;

    //---create a Button view---
    frame = CGRectMake(20, 60, 280, 50);
    button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = frame;
   [button setTitle:@“OK” forState:UIControlStateNormal];
   button.backgroundColor = [UlColor clearColor];

   //---add the views to the View window---
   [self.view addSubview:label];
   [self.view addSubview:button];
   [super viewDidLoad];
}

Answer to Question 3

//---add the action handler and set current class as target---
    [button addTarget:self
               action:@selector(buttonClicked:)
     forControlEvents:UIControlEventTouchUpInside];

    ...
    ...

-(IBAction) buttonClicked: (id) sender{
    //--add implementation here--
}

Answer to Question 4

In the HelloWorldViewController.m file, add the following code:

-(IBAction) buttonClicked: (id) sender{
    UIAlertView *alert =
        [[UIAlertView alloc] initWithTitle:@“Button Clicked!”
                                   message:@“Button was clicked!”
                                  delegate:self
                         cancelButtonTitle:@“OK”
                         otherButtonTitles:nil];
    [alert show];
    [alert release];
}
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering iOS 12 Programming - Third Edition

Mastering iOS 12 Programming - Third Edition

Donny Wals
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 9781118144251Purchase book