Design with iPhone Project 5: Alerts, sound, vibrate, pickers, multiview

Warning:
Content of this website may change at any time up until class meeting.

Project Topics


Preparation


Create a new iOS app in Xcode

p1fig-IosView.jpg
Fig. 1
p1fig-projWin1.jpg
Fig. 2 Xcode Workspace Window



Alerts 
p5fig-buttons1.jpg
Fig. 3

p4fig-outlet1.jpg
Fig. 4

 - (IBAction)myAlert:(id)sender { 
     myLabel.text=@"Alert Pressed";
     [self.view setNeedsDisplay];
     UIAlertView *alertv;
     alertv=[[UIAlertView alloc]
     initWithTitle:@"tpw Alert"
     message:@"message here" 
     delegate:nil
     cancelButtonTitle:@"Cancel"
     otherButtonTitles: nil];
     [alertv show];
     [alertv release];
}

p5fig-appSim1.jpg
Fig. 5
Adding the UIAlertViewDelegate Protocol
@interface project5tpwViewController : UIViewController <UIAlertViewDelegate> {

- (IBAction)myAlert:(id)sender {
    myLabel.text=@"Alert Pressed";
    [self.view setNeedsDisplay];
     UIAlertView *alertv;
     alertv=[[UIAlertView alloc]
     initWithTitle:@"tpw Alert"
     message:@"message here  \n \n" 
     delegate:self
     cancelButtonTitle:@"Cancel"
     otherButtonTitles:@"Cancel2" , nil];
     [alertv show];
     [alertv release];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex)
    {
        case 0:
            myLabel.text=@"AlertButton 0 Pressed";
           break;
        case 1:
            myLabel.text=@"AlertButton 1 Pressed";
            break;
    }
}

p5fig-appSim2.jpg
Fig. 6
p5fig-appSim3.jpg
Fig. 7

Action Sheets
@interface project5tpwViewController : UIViewController <UIAlertViewDelegate, UIActionSheetDelegate> {

- (IBAction)mySound:(id)sender {
 
    UIActionSheet *actionsheet;
    actionsheet=[[UIActionSheet alloc] initWithTitle:@"Available Actions"
                                            delegate:self
                                   cancelButtonTitle:@"Cancel1"
                              destructiveButtonTitle:nil
                                   otherButtonTitles:@"Sound1",@"Sound2",nil];
    actionsheet.actionSheetStyle=UIActionSheetStyleDefault;
    [actionsheet showInView:self.view];  

}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    switch (buttonIndex)
    {
        case 0:
            {myLabel.text=@"actionSheet 0 Pressed";
            SystemSoundID mysound;
            NSString *audiofile = [[NSBundle mainBundle] pathForResource:@"tpwSound1" ofType:@"wav"];
            AudioServicesCreateSystemSoundID((CFURLRef)
                                             [NSURL fileURLWithPath:audiofile]
                                             , &mysound);
            AudioServicesPlaySystemSound(mysound);
            [audiofile release];}
            break;
        case 1:
            {myLabel.text=@"actionSheet 1 Pressed";
            SystemSoundID mysound;
            NSString *audiofile = [[NSBundle mainBundle] pathForResource:@"tpwSound2" ofType:@"wav"];
            AudioServicesCreateSystemSoundID((CFURLRef)
                                             [NSURL fileURLWithPath:audiofile]
                                             , &mysound);
            AudioServicesPlaySystemSound(mysound);
            [audiofile release];  }        
            break;
        case 2:
            myLabel.text=@"actionSheet 2 Pressed";
            break;
    }
}

Audio and Sound
p5fig-playSoundEffects.jpg
Fig. 8
p5fig-addFiles.jpg
Fig. 9
p5fig-addFramework.jpg
Fig. 10
#import <AudioToolBox/AudioToolBox.h>
- (IBAction)myVib:(id)sender {
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
p5fig-appSim4.jpg
Fig. 11


Pickers
p5fig-datePick1.jpg
Fig. 12
p5fig-datePickWeb1.jpg
Fig. 13
@property (nonatomic, retain) IBOutlet UIDatePicker *myDate;            //outlet for datepicker
@property (nonatomic, retain) IBOutlet UIWebView *myWebView;    //outlet for webview
- (IBAction)myDateValueChanged:(id)sender;                                        //action added to date-picker
    NSDateFormatter *dateForm;
    NSString * mydate;
    dateForm = [[NSDateFormatter alloc] init];
    [dateForm setDateFormat:@"yyyy-MM-dd"];
    mydate = [dateForm stringFromDate:[sender date]];
    myLabel.text= [[NSString alloc] initWithFormat:@"date=%@", mydate];
    [dateForm release];
    NSURL * dateURL;
    NSURL * baseURL;
    NSDateFormatter *dateForm;
    NSString * mydate;
    baseURL=[[NSURL alloc] initWithString:@"http://campusevents.uncc.edu/events/"];
    dateForm = [[NSDateFormatter alloc] init];
    [dateForm setDateFormat:@"yyyy-MM-dd"];
    mydate = [dateForm stringFromDate:[sender date]];
    dateURL=[[NSURL alloc] initWithString:mydate relativeToURL:baseURL];
    [myWebView loadRequest:[NSURLRequest requestWithURL:dateURL]];
    [dateURL release];
p5fig-appSim5.jpg
Fig. 14


Multi-View Apps
p5fig-newTabBarApp.jpg
Fig. 15
p5fig-addTabViewCtrl1.jpg
Fig. 16
p5fig-addTabBarItem1.jpg
Fig. 17

p5fig-addSimuMetrics.jpg
Fig. 18
p5fig-TabBarItemSetClass.jpg
Fig. 19
   

p5fig-appSim6.jpg
Fig. 19

//  Project5tpwTabAppDelegate.h
#import <UIKit/UIKit.h>
@interface Project5tpwTabAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
p5fig-appSim7.jpg
Fig. 20




Demonstration



Report



Copyright 2011 by T.P. Weldon


Apple, iPhone, iPad, and Xcode  are registered trademarks of Apple Inc.