Home ? Source Code ? iPhone ComboBox

iPhone ComboBox

maninwest
2015-02-11 03:58:36
The author
View(s):
Download(s): 0
Point (s): 1?
Category Category:
MobileMobile Objective-CObjective-C

Description

Translated by [email protected] Author:Dor [email protected]
I was working on a project that required porting an Android application with many combo boxes into a native iPhone application. The requirements were to maintain the ported application look and feel; unfortunately iOS does not include a combobox control. The solution I came up with is aUITextFieldthat uses aUIPickerViewfor input instead of the keyboard, similar to the Safari implementation of an HTML select field.
Implementation

I’ve created aUIViewControllersubclass that contains aUITextFieldand an arrow image to make it look like a combo box.
When a user touches theUITextField, the following action is invoked:
- (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;  
}


-(void)doneClicked:(id)sender
{
    [textField resignFirstResponder]; //hides the pickerView }

Attached Source Code


iPhoneComboBox_src.zip contains the subclassedControllerViewfor easy integration with an existing project.
iPhoneComboBox_demo.zip contains the source code of a demo application that usesComboBox ControllerView.
Using the Code


Open Xcode and create a "Single View Application", name itComboBoxTest.
Make sure that "Use Automatic Reference Counting" is checked.
Download and unzip iPhoneComboBox_src.zip to a folder named ComboBox (double click on the zip file).
Drag and drop the ComboBox folder to the project in Xcode.
Make sure that "Copy items into destination groups's folder" is checked.
Make sure that "Create groups for any added folders" is checked.
Edit ViewController.h: Add#import "ComboBox.h", declareComboBox* combo1;
The header file should look like this:
#import  #import "ComboBox.h" @interface ViewController : UIViewController
{
    ComboBox* combo1;     
}
@end

Edit ViewController.m, add the following toviewDidLoad:
NSMutableArray* fruitsArray = [[NSMutableArray alloc] init];
[fruitsArray addObject:@"Apple"];
[fruitsArray addObject:@"Banana"];
[fruitsArray addObject:@"Orange"];
    
combo1 = [[ComboBox alloc] init];
[combo1 setComboData:fruitsArray]; //Assign the array to ComboBox [self.view addSubview:combo1.view];
combo1.view.frame = CGRectMake(110, 69, 120, 31); //ComboBox location and  //size (x,y,width,height)

Build and run, that's it.

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

Comments

(Add your comment, get 0.1 Point)
Minimum:15 words, Maximum:160 words
  • 1
  • Page 1
  • Total 1

iPhone ComboBox (45.58 kB)(7.41 kB)

Need 1 Point(s)
Your Point (s)

Your Point isn't enough.

Get 22 Point immediately by PayPal

Point will be added to your account automatically after the transaction.

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

Submit your source codes. Get more Points

LOGIN

Don't have an account? Register now
Need any help?
Mail to: [email protected]

切換到中文版?

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
全民欢乐捕鱼攻略技巧 pk10杀一码教程 推二八杠顺口溜 亿彩有多少人亏钱 福建时时结果查询 ig传统彩赛车怎么找规律 北京pk10走势图杀号技巧 澳洲幸运5官网大小单双玩法 北京pk10最好计划群 福彩3d胆拖投注表平台 球琛比分足球即时比分 加拿大28如何杀组合 足球比分直播即时比分 二中二6码有几组 手机版三公游戏赢现金 大赢家娱乐下载 重庆时时彩漏洞在哪