
在此之后我将这个tabledata数组传递给名为mytableVIEw的tableVIEw,我在dIDLoad方法中声明了表视图的高度.
我希望tableVIEw的高度根据表中元素的数量是动态的,
这是代码片段,
- (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];} 在dIDLoad中声明mytableVIEw:
mytableVIEw.frame=CGRectMake(550,00,220,400);
看截图,
在第一个图像数据中,但是,tableVIEw不会增加它的大小,而在第二个图像中只有1个数据,但高度仍在修复.
CGRect frame = mytableVIEw.frame;frame.size.height = MIN(40 * [tableData count],400); // 400 is the maximum height that the table vIEw can have. You can change it to whatever you likemytableVIEw.frame = frame;
如果这对您有用,请告诉我.
总结以上是内存溢出为你收集整理的ios – 无法在目标c中设置UITableView动态的高度全部内容,希望文章能够帮你解决ios – 无法在目标c中设置UITableView动态的高度所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)