David
David

Reputation: 137

Is there any real reason to use a UiSearchBar over a Uitextfield?

I was curious if I would be able to use a Uitextfield instead of a UiSearchBar because of the ease of resizing and the look. Are there any real drawbacks?

Upvotes: 4

Views: 734

Answers (2)

Abhinandan Pratap
Abhinandan Pratap

Reputation: 2148

No there is no real drawback to use UITExtField as an UISearchBar. You just only need to add UITableView,UISearchBar datasource and Delegate methods.

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
     if (textField == your textfield) 
{
    [textField resignFirstResponder];
    yourtableview.hidden = NO;
    return YES; 
}

}
return  YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
     //....
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
     //...
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
     //...
}

Upvotes: 3

Fahri Azimov
Fahri Azimov

Reputation: 11770

Actually, no, no such reasons. Depends on what you are going to do. UISearchBar is more optimized for searching, with its' look, functions, and callback methods. If you have to create custom interface element for searching, you would better start with UITextField with a few UIButtons, UISegmentedControls, whatever it takes.

Upvotes: 5

Related Questions