2011-09-24 2 views
0

J'ai une tableView et je veux appliquer la fonction de recherche sur tableView. Pour cela j'ai besoin de textField et de Search Button mais je ne sais pas comment les créer par programmation. Alors, dis-moi comment créer ces deux outils.comment ajouter du texte et un bouton par programme?

merci.

Répondre

0

Voici la documentation pour UITextField et UIButton. Vous pouvez également trouver UISearchBar utile, qui incorpore à la fois un champ de texte et un bouton.

Ajoutez votre point de vue à l'en-tête de la vue Table.

0

Vous avez un délégué de table tableview:cellForRowAtIndexPath. Dans ce délégué, ajoutez le code suivant.

//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]; 
} 

Vous pouvez aussi ajouter un événement pour le bouton comme

[btnSearch addTarget:self action:@selector(eventName) forControlEvents:UIControlEventTouchUpInside]; 

Merci

Questions connexes