Home » Source Code » iPhone ComboBox » ComboBox.m

ComboBox.m ( File view )

  • By maninwest 2015-02-11
  • View(s):21
  • Download(s):0
  • Point(s): 1
			//
//  ComboBox.m
//
//  Created by Dor Alon on 12/17/11.
//  http://doralon.net

#import "ComboBox.h"


@implementation ComboBox

@synthesize selectedText;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{

    return [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

}

- (void)didReceiveMemoryWarning
{

    [super didReceiveMemoryWarning];

}


#pragma mark - View lifecycle

- (void)viewDidLoad
{

    [super viewDidLoad];

}

- (void)viewDidUnload
{

    [super viewDidUnload];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}


//-- UIPickerViewDelegate, UIPickerViewDataSource

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{

    return 1;

}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{

    textField.text = [dataArray objectAtIndex:row];
    selectedText = textField.text;

}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{

    return [dataArray count];

}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{

    return [dataArray objectAtIndex:row];

}

//-- ComboBox


-(void) setComboData:(NSMutableArray*) data
{

    dataArray = data;    

}


-(void)doneClicked:(id) sender
{

    [textField resignFirstResponder]; //hides the pickerView

}


- (IBAction)showPicker:(id)sender {

    
    pickerView = [[UIPickerView alloc] init];
    pickerView.showsSelectionIndicator = YES;
    pickerView.dataSource = self;
    pickerView.delegate = self;

    UIToolbar* toolbar = [[UIToolbar alloc] init];
    toolbar.barStyle = UIBarStyleBlackTranslucent;
    [toolbar sizeToFit];
    
    //to make the done button aligned to the right
    UIBarButtonItem *flexibleSpaceLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    
    
    UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                                   style:UIBarButtonItemStyleDone target:self
                                                                  action:@selector(doneClicked:)];
    
    
    [toolbar setItems:[NSArray arrayWithObjects:flexibleSpaceLeft, doneButton, nil]];

    //custom input view
    textField.inputView = pickerView;
    textField.inputAccessoryView = toolbar;  

}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)aTextField
{

    [self showPicker:aTextField];
    return YES;

}

@end
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
01.96 kB
.DS_Store6.00 kB2012-03-12 06:47
01.96 kB
01.96 kB
._.DS_Store244.00 B2012-03-12 06:47
01.96 kB
.DS_Store6.00 kB2012-03-12 06:48
01.96 kB
._.DS_Store244.00 B2012-03-12 06:48
AppDelegate.h330.00 B2011-12-17 09:13
._AppDelegate.h295.00 B2011-12-17 09:13
AppDelegate.m2.36 kB2011-12-17 09:13
._AppDelegate.m295.00 B2011-12-17 09:13
01.96 kB
.DS_Store6.00 kB2011-12-17 09:14
01.96 kB
._.DS_Store244.00 B2011-12-17 09:14
arrow.png1.34 kB2011-12-17 04:12
._arrow.png244.00 B2011-12-17 04:12
ComboBox.h472.00 B2012-03-12 06:45
._ComboBox.h171.00 B2012-03-12 06:45
ComboBox.m2.62 kB2012-03-12 07:27
._ComboBox.m171.00 B2012-03-12 07:27
ComboBox.xib9.35 kB2012-03-12 07:24
._ComboBox244.00 B2012-03-12 07:27
ComboBoxTest-Info.plist1.07 kB2011-12-17 04:15
._ComboBoxTest-Info.plist244.00 B2011-12-17 04:15
ComboBoxTest-Prefix.pch327.00 B2011-12-17 04:15
._ComboBoxTest-Prefix.pch295.00 B2011-12-17 04:15
01.96 kB
.DS_Store6.00 kB2011-12-17 09:14
01.96 kB
._.DS_Store244.00 B2011-12-17 09:14
InfoPlist.strings45.00 B2011-12-17 04:15
._InfoPlist.strings295.00 B2011-12-17 04:15
ViewController.xib13.91 kB2012-03-12 07:04
._en.lproj244.00 B2012-03-12 07:04
main.m302.00 B2011-12-17 09:13
._main.m295.00 B2011-12-17 09:13
ViewController.h349.00 B2012-03-12 07:10
._ViewController.h171.00 B2012-03-12 07:10
ViewController.m3.02 kB2011-12-17 09:11
._ViewController.m295.00 B2011-12-17 09:11
._ComboBoxTest244.00 B2012-03-12 07:10
01.96 kB
project.pbxproj12.93 kB2011-12-17 04:15
01.96 kB
._project.pbxproj244.00 B2011-12-17 04:15
01.96 kB
contents.xcworkspacedata157.00 B2011-12-17 04:15
01.96 kB
._contents.xcworkspacedata244.00 B2011-12-17 04:15
01.96 kB
01.96 kB
UserInterfaceState.xcuserstate17.13 kB2012-03-12 07:28
01.96 kB
._doralon.xcuserdatad244.00 B2012-03-12 07:28
._xcuserdata244.00 B2011-12-17 04:15
._project.xcworkspace244.00 B2011-12-17 04:15
01.96 kB
01.96 kB
01.96 kB
Breakpoints.xcbkptlist91.00 B2012-03-12 07:25
01.96 kB
ComboBoxTest.xcscheme3.04 kB2011-12-17 04:15
01.96 kB
01.96 kB
01.96 kB
._ComboBoxTest.xcscheme244.00 B2011-12-17 04:15
xcschememanagement.plist484.00 B2011-12-17 04:15
._xcschememanagement.plist244.00 B2011-12-17 04:15
._xcschemes244.00 B2011-12-17 04:15
._doralon.xcuserdatad244.00 B2012-03-12 07:08
._xcuserdata244.00 B2011-12-17 04:15
._ComboBoxTest244.00 B2012-03-12 06:44
...
Sponsored links

ComboBox.m (45.58 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D