iPhone
iPhone

Reputation: 4170

how to add textfield and button programmatically?

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 programmatically. so plz tell me how to create these two tools.

thanx.

Upvotes: 0

Views: 2034

Answers (3)

DShah
DShah

Reputation: 9876

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

Upvotes: 1

iphonedev23
iphonedev23

Reputation: 991

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

Upvotes: 0

August Lilleaas
August Lilleaas

Reputation: 54603

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.

Upvotes: 0

Related Questions