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.
- @ Interface Set_starViewController: UIViewController <UIPickerViewDelegate> {
- UIPickerView * pickerview;
- UILabel * contentview;
- NSArray * content; // Constellation
- Id _ delegate;
- Int _ type;
- }
- -(Id) initWithDelegate :( id) delegate type :( int) type;
- -(Void) setString :( id) sender;
- @ End
- // Set_starViewController.m
- //
- // Created by AmorYin on 10-11-23.
- // Copy 2010 _ MyCompanyName _. All rights reserved.
- //
- # Import "Set_starViewController.h"
- @ Implementation Set_starViewController
- -(Id) initWithDelegate :( id) delegate type :( int) type
- {
- Self = [super init];
- If (self! = Nil ){
- UILabel * titleText = [[UILabel alloc] initWithFrame: CGRectMake (0, 0,200, 20)];
- TitleText. backgroundColor = [UIColor clearColor];
- TitleText. textAlignment = UITextAlignmentCenter;
- TitleText. textColor = [UIColor colorWithRed: 0.33 green: 0.33 blue: 0.33 alpha: 1.0];
- [TitleText setFont: [UIFont systemFontOfSize: 15.0];
- [TitleText setText: @ "constellation"];
- Self. navigationItem. titleView = titleText;
- [TitleText release];
- _ Delegate = delegate;
- UIButton * back = [[UIButton alloc] initWithFrame: CGRectMake (0.0, 0.0, 62.0, 32.0)];
- [Back setBackgroundImage: [UIImage imageNamed: @ ".png"] forState: UIControlStateNormal];
- [Back setBackgroundImage: [UIImage imageNamed: @ ".png"] forState: UIControlStateHighlighted];
- [Back setBackgroundImage: [UIImage imageNamed: @ ".png"] forState: UIControlStateDisabled];
- [Back addTarget: _ delegate
- Action: @ selector (backView)
- ForControlEvents: UIControlEventTouchUpInside];
- UIBarButtonItem * add = [[UIBarButtonItem alloc] initWithCustomView: back];
- [[Self navigationItem] setLeftBarButtonItem: add];
- [Add release];
- [Back release];
- UIBarButtonItem * save = nil;
- Save = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemSave
- Target: self
- Action: @ selector (setString :)];
- Self. navigationItem. rightBarButtonItem = save;
- Save = nil;
- [Save release];
- If (type = 0 ){
- Content = [[NSArray alloc] initWithObjects: @ "Aquarius", @ "Pisces", @ "Aries", @ "Taurus"
- , @ "Gemini", @ "cancer", @ "Leo", @ "Virgo"
- , @ "Libra", @ "scorpio", @ "Sagittarius", @ "goat's seat", nil];
- _ Type = 0;
- } Else {
- Content = [[NSArray alloc] initWithObjects: @ "", @ "", @ "MBA", @ "master"
-
- , @ "Others", nil];
- _ Type = 1;
- }
- }
- Return self;
- }
-
- -(Void) loadView
- {
- UIView * myview = [[UIView alloc] initWithFrame: [UIScreen mainScreen]. applicationFrame] autorelease];
- Myview. autoresizesSubviews = YES;
- [Myview setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: @ "background.png"];
- Self. view = myview;
- // Set the selector
- Pickerview = [[UIPickerView alloc] initWithFrame: CGRectMake (0.0, 150.0, 320.0, 216.0)];
- Pickerview. delegate = self;
- Pickerview. showsSelectionIndicator = YES;
- [Self. view addSubview: pickerview];
- Contentview = [[UILabel alloc] initWithFrame: CGRectMake (80.0, 80.0, 100.0, 40.0)];
- Contentview. backgroundColor = [UIColor clearColor];
- [Self. view addSubview: contentview];
-
- }
-
- -(Void) didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
- [Super didReceiveMemoryWarning];
- // Release any cached data, images, etc that aren't in use.
- }
- -(Void) viewDidUnload {
- [Super viewDidUnload];
- // Release any retained subviews of the main view.
- // E.g. self. myOutlet = nil;
- }
- -(Void) dealloc {
- [Super dealloc];
- [Contentview release];
- [Pickerview release];
- [Content release];
- }
-
- # Pragma mark-
- # Pragma mark Processing Method
- // Returns the number of columns displayed.
- -(NSInteger) numberOfComponentsInPickerView :( UIPickerView *) pickerView
- {
- Return 1;
- }
- // Returns the number of rows displayed in the current column.
-
- -(NSInteger) pickerView :( UIPickerView *) pickerView numberOfRowsInComponent :( NSInteger) component
- {
- Return [content count];
- }
- // Set the content of the current row. If the row is not displayed, the row is automatically released.
- -(NSString *) pickerView :( UIPickerView *) pickerView titleForRow :( NSInteger) row forComponent :( NSInteger) component
- {
- Return [content objectAtIndex: row];
- }
- -(Void) pickerView :( UIPickerView *) pickerView didSelectRow :( NSInteger) row inComponent :( NSInteger) component
- {
- // NSString * result = [pickerView: pickerView titleForRow: row forComponent: component];
- NSString * result = nil;
- Result = [content objectAtIndex: row];
- NSLog (@ "result: % @", result );
- Contentview. text = result;
- [Result release];
- }
-
- -(Void) setString :( id) sender
- {
- // Transfer value
- If (_ type = 0 ){
- [_ Delegate setSomthing: contentview. text name: @ "star"];
- } Else {
- [_ Delegate setSomthing: contentview. text name: @ "xueli"];
- }
- [Self. navigationController popViewControllerAnimated: YES];
- [Self. navigationController pushViewController: _ delegate animated: YES];
- [Self. navigationController setNavigationBarHidden: NO];
- }
- @ End
Summary:IPhoneApplication DevelopmentUIPickerViewUseDEMOI hope this article will be helpful to you!