我有一個tableView,我想在tableView上應用搜索工具。爲此,我需要textField和搜索按鈕,但我不知道如何以編程方式創建這些。所以請告訴我如何創建這兩個工具。如何以編程方式添加文本字段和按鈕?
thanx。
我有一個tableView,我想在tableView上應用搜索工具。爲此,我需要textField和搜索按鈕,但我不知道如何以編程方式創建這些。所以請告訴我如何創建這兩個工具。如何以編程方式添加文本字段和按鈕?
thanx。
與下面的鏈接,它描述了異步滾動例如
但你可以嘗試爲按鈕添加事件另請參閱前一篇文章 UISearchBar Sample Code
爲執行並得到結果,當您鍵入的更多的方法,去蘋果的文檔和參考UISearchBarDelegate Protocol Methods
以下是UITextField和UIButton的文檔。您也許會發現UISearchBar有用,它包含文本字段和按鈕。
將您的意見添加到表視圖的標題視圖。
您有一個表代表tableview:cellForRowAtIndexPath
。在這個委託中添加下面的代碼。
//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];
}
,你也可以像
[btnSearch addTarget:self action:@selector(eventName) forControlEvents:UIControlEventTouchUpInside];
感謝