私はsearchBarデータをデータベースから取得している、私はsearchBarを使用してiPadアプリケーションを作成し、私はtableDataという配列に格納しています。は、目的のcのUITableView動的の高さを設定することができません
このtabledata配列をmyTableViewというtableViewに渡した後、私はdidLoadメソッドのテーブルビューの高さを宣言しました。
IはdidLoadでmyTableViewの
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
// only show the status bar’s cancel button while in edit mode
sBar.autocorrectionType = UITextAutocorrectionTypeNo;
// flush the previous search content
[tableData removeAllObjects];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
sBar.showsCancelButton = NO;
[myTableView setHidden:TRUE];
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[myTableView setHidden:FALSE];
[tableData removeAllObjects];// remove all data that belongs to previous search
myTableView.backgroundColor=[[UIColor alloc]initWithRed:4.0/255 green:24.0/255 blue:41.0/255 alpha:1.0];
[self.view bringSubviewToFront:myTableView];
if([searchText isEqualToString:@""]||searchText==nil){
[myTableView setHidden:TRUE];
[myTableView reloadData];
return;
}
NSInteger counter = 0;
for(NSString *name in arr)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
NSRange r = [name rangeOfString:searchText options:NSCaseInsensitiveSearch];
if(r.location != NSNotFound)
{
if(r.location== 0)//that is we are checking only the start of the naames.
{
[tableData addObject:name];
}
}
counter++;
[pool release];
}
[myTableView reloadData];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
// if a valid search was entered but the user wanted to cancel, bring back the main list content
[tableData removeAllObjects];
@try{
[myTableView reloadData];
}
@catch(NSException *e){
}
[sBar resignFirstResponder];
sBar.text = @"";
}
// called when Search (in our case “Done”) button pressed
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
[myTableView reloadData];
}
が宣言のtableViewの高さは、テーブル内の要素の数に応じて、ここで
は、コードスニペットで動的になりたい:
myTableView.frame=CGRectMake(550, 00, 220,400);
スクリーンショットを参照してください、最初の画像データには がありますが、tableViewはサイズを増やさず、2番目の画像には1つのデータしかありませんが高さですまだ修正されています。
あなたの質問のタイトルが間違っていると思います。私の理解から、あなたは 'UISearchBar'のものではなく、tableViewの高さを変更したいと思います - 私は間違っていますか? –
YEs ............ – GAMA