是否有任何这样的方法或解决方案可以自动调整表观的行高度,具体取决于内容。我的意思是我不想指定行高度,并且需要根据该的内容来指定行高度如果没有这样的方法,请告诉我解决方案,当设备的方向更改时,我该如何更改高度?
您必须找到内容的高度并可以使用
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return "your content height + your padding height value";
}
在方向上更改只需重新加载您的表观视图即可。
检查一下
// --dynamic cell height according to the text--
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *text = <your text>;
CGSize constraint = CGSizeMake(210, 20000.0f);
CGSize size = [text sizeWithFont:[UIFont fontWithName:@"Helvetica-Light" size:14] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
// constratins the size of the table row according to the text
CGFloat height = MAX(size.height,60);
return height + (15);
// return the height of the particular row in the table view
}
希望这会有所帮助
编辑您是否尝试过此方法?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
否则,如果您的表单元格自定义标签和图像视图等,则可以使用setAutoresizingmask:在每个上自动调整到方向。
[yourview setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
您可以实现 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
uitaiteView的委托方法。
,如果您的Google Google,您应该可以找到很多有关它的教程。
以下是:
http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/
您必须使用:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
是的 - 我知道您非常了解这种方法,而且我已经仔细阅读了您的问题。
- 您必须使用该委托方法来动态控制行的高度。我的建议是从您的后端数据模型中检查每个单元格的内容,并返回一个适合该单元格的数字:
NSDictionary *thisCell = (NSDictionary *)[myArray objectAtIndexPath:indexPath.row];
NSString *myCellContents = [thisCell valueForKey:@"MyStringIWantToCheckOut"];
if ([mycellContents length] > 25) {
return 80;
} else {
return 40;
}
在方向发生变化时,您必须在委托方法中这样做:
-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
然后在TableView
上射击reloadData
。
- (CGFloat)tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row){
case 0:
if(indexPath.section == 0)
//title
return 75;
default:
return 75;
}
}
func tableview(_ Height forrowAttableView:uitableview,height forporrowat indexpath:indexpath) -> cgfloat { 返回uitableviewautomentimension }
对于行的动态高度,否则您可以给出静态高度,而不是" uitaiteViewAutomationDimension"