Control_FunViewController.m
上传用户:jjjjag8
上传日期:2017-04-17
资源大小:1443k
文件大小:4k
源码类别:

iPhone

开发平台:

MultiPlatform

  1. //
  2. //  Control_FunAppDelegate.m
  3. //  Control Fun
  4. //
  5. //  Created by Jeff LaMarche on 7/2/08.
  6. //  Copyright __MyCompanyName__ 2008. All rights reserved.
  7. //
  8. #import "Control_FunViewController.h"
  9. @implementation Control_FunViewController
  10. @synthesize nameField;
  11. @synthesize numberField;
  12. @synthesize sliderLabel;
  13. @synthesize leftSwitch;
  14. @synthesize rightSwitch;
  15. @synthesize switchView;
  16. @synthesize doSomethingButton;
  17. - (void)viewDidLoad
  18. {
  19. UIImage *buttonImageNormal = [UIImage imageNamed:@"whiteButton.png"];
  20. UIImage *stretchableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
  21. [doSomethingButton setBackgroundImage:stretchableButtonImageNormal forState:UIControlStateNormal];
  22. UIImage *buttonImagePressed = [UIImage imageNamed:@"blueButton.png"];
  23. UIImage *stretchableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
  24. [doSomethingButton setBackgroundImage:stretchableButtonImagePressed forState:UIControlStateHighlighted];
  25. }
  26. - (IBAction)doSomething:(id)sender
  27. {
  28. UIActionSheet *actionSheet = [[UIActionSheet alloc] 
  29.   initWithTitle:@"Are you sure?" 
  30.   delegate:self 
  31.   cancelButtonTitle:@"No Way!"
  32.   destructiveButtonTitle:@"Yes, I'm Sure!" 
  33.   otherButtonTitles:nil];
  34. [actionSheet showInView:self.view];
  35. [actionSheet release];
  36. }
  37. - (void)actionSheet:(UIActionSheet *)actionSheet
  38. didDismissWithButtonIndex:(NSInteger)buttonIndex
  39. {
  40. if (!buttonIndex == [actionSheet cancelButtonIndex])
  41. {
  42. NSString *msg = nil;
  43. if (nameField.text.length > 0)
  44. msg = [[NSString alloc] initWithFormat:@"You can breathe easy, %@, everything went OK.", nameField.text];
  45. else
  46. msg = @"You can breathe easy, everything went OK.";
  47. UIAlertView *alert = [[UIAlertView alloc] 
  48.   initWithTitle:@"Something was done" 
  49.   message:msg 
  50.   delegate:self 
  51.   cancelButtonTitle:@"Phew!" 
  52.   otherButtonTitles:nil];
  53. [alert show];
  54. [alert release];
  55. [msg release];
  56. }
  57. }
  58. - (IBAction)switchChanged:(id)sender
  59. {
  60. UISwitch *whichSwitch = (UISwitch *)sender;
  61. BOOL setting = whichSwitch.isOn;
  62. [leftSwitch setOn:setting animated:YES];
  63. [rightSwitch setOn:setting animated:YES];
  64. }
  65. - (IBAction)toggleShowHide:(id)sender
  66. {
  67. UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
  68. NSInteger segment = segmentedControl.selectedSegmentIndex;
  69. if (segment == kShowSegmentIndex) [switchView setHidden:NO];
  70. else [switchView setHidden:YES];
  71. }
  72. - (IBAction)sliderChanged:(id)sender
  73. {
  74. UISlider *slider = (UISlider *)sender;
  75. int progressAsInt = (int)(slider.value + 0.5f);
  76. NSString *newText = [[NSString alloc] initWithFormat:@"%d", progressAsInt];
  77. sliderLabel.text = newText;
  78. [newText release];
  79. }
  80. - (IBAction)backgroundClick:(id)sender
  81. {
  82. [nameField resignFirstResponder];
  83. [numberField resignFirstResponder];
  84. }
  85. - (IBAction)textFieldDoneEditing:(id)sender
  86. {
  87. [sender resignFirstResponder];
  88. }
  89. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  90. // Return YES for supported orientations
  91. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  92. }
  93. - (void)didReceiveMemoryWarning {
  94. [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
  95. // Release anything that's not essential, such as cached data
  96. }
  97. - (void)dealloc {
  98. // In Chapter 4, we forgot to mention the need
  99. // to release the outlets, since we declared the 
  100. // properties with the retain keyword, it is important
  101. // to release these here to avoid leaking memory.
  102. // In this example, since it is a single-view application
  103. // this code will only fire when the application is 
  104. // terminating, but it is good form to keep your memory
  105. // clean even when it doesn't have a functional impact
  106. // on your application.
  107. [nameField release];
  108. [numberField release];
  109. [sliderLabel release];
  110. [leftSwitch release];
  111. [rightSwitch release];
  112. [switchView release];
  113. [doSomethingButton release];
  114. [super dealloc];
  115. }
  116. @end