Can we set the dropdown list for the textfield to select an option in iphone sdk?
I need a textfield which has an dropdown list to select an option from that.Is there any possib开发者_JS百科le chances to do that in Iphone sdk?
Guys I need a quick help from ur side.
Anyone's help will be much appreciated.
Thank you, Monish.
You use a UIPickerView instead of a dropdown list.
Edit: i missed the text field part. You are emulating a combo box.
You can use a picker + text field, and fill the text field from the pickerView:didSelectRow:inComponent delegat method
Edit2: There are some S/O questions about this already - related to UIPickerView bugs
-(void)textFieldDidBeginEditing:(UITextField *)textField{
[self gotodropdown];
}
-(void)dropdown
{
if(dropDownView==nil && ([copyListOfItems count] > 0))
{
dropDownView = [[DropDownView alloc] initWithArrayData:copyListOfItems heightTableView:200 paddingTop:0 paddingLeft:0 paddingRight:0 refView:textField animation:BOTH openAnimationDuration:2 closeAnimationDuration:0.5 ];
dropDownView.delegate = self;
[dropDownView openAnimation];
[self addSubview:dropDownView.view];
}
}
//dropdown.m
- (id)initWithArrayData:(NSMutableArray *)data heightTableView:(CGFloat)tHeightTableView paddingTop:(CGFloat)tPaddingTop paddingLeft:(CGFloat)tPaddingLeft paddingRight:(CGFloat)tPaddingRight refView:(UIView*)rView animation:(AnimationType)tAnimation openAnimationDuration:(CGFloat)openDuration closeAnimationDuration:(CGFloat)closeDuration {
if ((self = [super init])) {
//array=[[NSMutableArray alloc]init];
//[array addObjectsFromArray:data];
self.array = [data retain];
NSLog(@"ARRAYIS:%@",data);
self.refView = rView;
self.paddingTop = tPaddingTop;
self.paddingLeft = tPaddingLeft;
self.paddingRight = tPaddingRight;
self.heightTableView = tHeightTableView;
self.open = openDuration;
self.close = closeDuration;
CGRect refFrame = refView.frame;
self.view.frame = CGRectMake(refFrame.origin.x-paddingLeft,refFrame.origin.y+refFrame.size.height+paddingTop,refFrame.size.width+paddingRight, heightTableView);
self.view.layer.shadowColor = [[UIColor blackColor] CGColor];
self.view.layer.shadowOffset = CGSizeMake(5.0f, 5.0f);
self.view.layer.shadowOpacity =1.0f;
self.view.layer.shadowRadius = 5.0f;
animationType = tAnimation;
}
return self;
}
use tableview delegate for further details
精彩评论