I have a tableView and I want to apply search facility on tableView. For that I require textField and search Button but I don't know how to create these program开发者_StackOverflow社区matically. so plz tell me how to create these two tools.
thanx.
Try with the following link which describes for asynchronous scrollbar example
http://blog.patrickcrosby.com/2010/04/27/iphone-ipad-uisearchbar-uisearchdisplaycontroller-asynchronous-example.html
But you can also refer the previous post UISearchBar Sample Code
For more methods of implementing and getting results as you type, go to apples document and refer UISearchBarDelegate Protocol Methods
Here's the documentation for UITextField and UIButton. You might also find UISearchBar useful, which incorporates both a text field and a button.
Add your views to the table view's header view.
You have a table delegate tableview:cellForRowAtIndexPath
. In this delegate add the following code.
//Suppose you want to add textfield and button at the first row
if(indexPath.Row == 0)
{
UITextField *txtSearch = [UITextField alloc] initWithFrame:CGRectMake(0,0,150,35)];
UIButton *btnSearch = [UIButton buttonWithType:UIButtoTypeCustom];
btnSearch.frame = CGRectMake(160,0,50,35);
[[cell contentView] addSubView:txtSearch];
[[cell contentView] addSubView:btnSearch];
}
Also You can add event for button like
[btnSearch addTarget:self action:@selector(eventName) forControlEvents:UIControlEventTouchUpInside];
Thanks
精彩评论