UIPickerView DEMO for iPhone application development

Source: Internet
Author: User

IPhoneApplication DevelopmentUIPickerViewUseDEMOIt is the content to be introduced in this article. This article mainly describes the implementation of Selector Based on code implementation. Select the Chinese zodiac and academic qualificationsUIPickerViewFor more information, see.

 
 
  1. @ Interface Set_starViewController: UIViewController <UIPickerViewDelegate> {
  2. UIPickerView * pickerview;
  3. UILabel * contentview;
  4. NSArray * content; // Constellation
  5. Id _ delegate;
  6. Int _ type;
  7. }
  8. -(Id) initWithDelegate :( id) delegate type :( int) type;
  9. -(Void) setString :( id) sender;
  10. @ End
  11. // Set_starViewController.m
  12. //
  13. // Created by AmorYin on 10-11-23.
  14. // Copy 2010 _ MyCompanyName _. All rights reserved.
  15. //
  16. # Import "Set_starViewController.h"
  17. @ Implementation Set_starViewController
  18. -(Id) initWithDelegate :( id) delegate type :( int) type
  19. {
  20. Self = [super init];
  21. If (self! = Nil ){
  22. UILabel * titleText = [[UILabel alloc] initWithFrame: CGRectMake (0, 0,200, 20)];
  23. TitleText. backgroundColor = [UIColor clearColor];
  24. TitleText. textAlignment = UITextAlignmentCenter;
  25. TitleText. textColor = [UIColor colorWithRed: 0.33 green: 0.33 blue: 0.33 alpha: 1.0];
  26. [TitleText setFont: [UIFont systemFontOfSize: 15.0];
  27. [TitleText setText: @ "constellation"];
  28. Self. navigationItem. titleView = titleText;
  29. [TitleText release];
  30. _ Delegate = delegate;
  31. UIButton * back = [[UIButton alloc] initWithFrame: CGRectMake (0.0, 0.0, 62.0, 32.0)];
  32. [Back setBackgroundImage: [UIImage imageNamed: @ ".png"] forState: UIControlStateNormal];
  33. [Back setBackgroundImage: [UIImage imageNamed: @ ".png"] forState: UIControlStateHighlighted];
  34. [Back setBackgroundImage: [UIImage imageNamed: @ ".png"] forState: UIControlStateDisabled];
  35. [Back addTarget: _ delegate
  36. Action: @ selector (backView)
  37. ForControlEvents: UIControlEventTouchUpInside];
  38. UIBarButtonItem * add = [[UIBarButtonItem alloc] initWithCustomView: back];
  39. [[Self navigationItem] setLeftBarButtonItem: add];
  40. [Add release];
  41. [Back release];
  42. UIBarButtonItem * save = nil;
  43. Save = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemSave
  44. Target: self
  45. Action: @ selector (setString :)];
  46. Self. navigationItem. rightBarButtonItem = save;
  47. Save = nil;
  48. [Save release];
  49. If (type = 0 ){
  50. Content = [[NSArray alloc] initWithObjects: @ "Aquarius", @ "Pisces", @ "Aries", @ "Taurus"
  51. , @ "Gemini", @ "cancer", @ "Leo", @ "Virgo"
  52. , @ "Libra", @ "scorpio", @ "Sagittarius", @ "goat's seat", nil];
  53. _ Type = 0;
  54. } Else {
  55. Content = [[NSArray alloc] initWithObjects: @ "", @ "", @ "MBA", @ "master"
  56.  
  57. , @ "Others", nil];
  58. _ Type = 1;
  59. }
  60. }
  61. Return self;
  62. }
  63.  
  64. -(Void) loadView
  65. {
  66. UIView * myview = [[UIView alloc] initWithFrame: [UIScreen mainScreen]. applicationFrame] autorelease];
  67. Myview. autoresizesSubviews = YES;
  68. [Myview setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: @ "background.png"];
  69. Self. view = myview;
  70. // Set the selector
  71. Pickerview = [[UIPickerView alloc] initWithFrame: CGRectMake (0.0, 150.0, 320.0, 216.0)];
  72. Pickerview. delegate = self;
  73. Pickerview. showsSelectionIndicator = YES;
  74. [Self. view addSubview: pickerview];
  75. Contentview = [[UILabel alloc] initWithFrame: CGRectMake (80.0, 80.0, 100.0, 40.0)];
  76. Contentview. backgroundColor = [UIColor clearColor];
  77. [Self. view addSubview: contentview];
  78.  
  79. }
  80.  
  81. -(Void) didReceiveMemoryWarning {
  82. // Releases the view if it doesn't have a superview.
  83. [Super didReceiveMemoryWarning];
  84. // Release any cached data, images, etc that aren't in use.
  85. }
  86. -(Void) viewDidUnload {
  87. [Super viewDidUnload];
  88. // Release any retained subviews of the main view.
  89. // E.g. self. myOutlet = nil;
  90. }
  91. -(Void) dealloc {
  92. [Super dealloc];
  93. [Contentview release];
  94. [Pickerview release];
  95. [Content release];
  96. }
  97.  
  98. # Pragma mark-
  99. # Pragma mark Processing Method
  100. // Returns the number of columns displayed.
  101. -(NSInteger) numberOfComponentsInPickerView :( UIPickerView *) pickerView
  102. {
  103. Return 1;
  104. }
  105. // Returns the number of rows displayed in the current column.
  106.  
  107. -(NSInteger) pickerView :( UIPickerView *) pickerView numberOfRowsInComponent :( NSInteger) component
  108. {
  109. Return [content count];
  110. }
  111. // Set the content of the current row. If the row is not displayed, the row is automatically released.
  112. -(NSString *) pickerView :( UIPickerView *) pickerView titleForRow :( NSInteger) row forComponent :( NSInteger) component
  113. {
  114. Return [content objectAtIndex: row];
  115. }
  116. -(Void) pickerView :( UIPickerView *) pickerView didSelectRow :( NSInteger) row inComponent :( NSInteger) component
  117. {
  118. // NSString * result = [pickerView: pickerView titleForRow: row forComponent: component];
  119. NSString * result = nil;
  120. Result = [content objectAtIndex: row];
  121. NSLog (@ "result: % @", result );
  122. Contentview. text = result;
  123. [Result release];
  124. }
  125.  
  126. -(Void) setString :( id) sender
  127. {
  128. // Transfer value
  129. If (_ type = 0 ){
  130. [_ Delegate setSomthing: contentview. text name: @ "star"];
  131. } Else {
  132. [_ Delegate setSomthing: contentview. text name: @ "xueli"];
  133. }
  134. [Self. navigationController popViewControllerAnimated: YES];
  135. [Self. navigationController pushViewController: _ delegate animated: YES];
  136. [Self. navigationController setNavigationBarHidden: NO];
  137. }
  138. @ End

Summary:IPhoneApplication DevelopmentUIPickerViewUseDEMOI hope this article will be helpful to you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.