我有一个UIScrollView,我动态填充标签。这发生在'setDetails'方法中。
我也有一个按钮,触发一个segue。使用UINavigationController,我可以使用“后退”按钮返回第一个视图。当我回去时,我不能再将UIScrollView滚动到最后。它以某种方式失去了他的内容高度。奇怪的是:当我再次执行setDetails时,(相同的内容)它并没有解决问题。如果我用其他数据执行setDetails,问题就解决了......
任何知道我能做什么的人?我几乎尝试了一切。谷歌没有帮助我很多:))
谢谢
这是填充滚动视图的方法。(_ detailScroll)。这是我在故事板上添加的滚动视图。它计算scrollview的内容大小。
这个方法由'sub'viewcontroller调用。
-(void)setDetails:(GFilm*) gFilm
{
//REMOVING LABELS
[titleCast removeFromSuperview];
titleCast = nil;
[titlePlot removeFromSuperview];
titlePlot = nil;
[titleRegie removeFromSuperview];
titleRegie = nil;
[regie removeFromSuperview];
regie = nil;
[cast removeFromSuperview];
cast = nil;
[plot removeFromSuperview];
plot = nil;
//SCROLL TO TOP
[_detailScroll scrollToTop];
//MAKING LABELS
CGFloat upX = 15;
CGFloat upY = 0;
CGRect rectTitleRegie = CGRectMake(upX, upY, 100, 16);
titleRegie = [[UILabel alloc]initWithFrame:rectTitleRegie];
titleRegie.numberOfLines = 1;
titleRegie.font = [titleRegie.font fontWithSize:12];
titleRegie.text = @"Regie:";
titleRegie.textColor = [UIColor colorWithRed:255/255.0f green:160/255.0f blue:8/255.0f alpha:1];
CGRect rectRegie = titleRegie.frame;
rectRegie.origin.x += 40;
rectRegie.size.width = self.view.frame.size.width - _detailScroll.frame.origin.x - rectRegie.origin.x - upX;
regie = [[UILabel alloc] initWithFrame:rectRegie];
regie.font = [regie.font fontWithSize:12];
regie.textColor = [UIColor whiteColor];
NSMutableString* reg = [[NSMutableString alloc]init];
for(int i = 0; i < gFilm.directorList.count; i++)
{
Director* d = [gFilm.directorList objectAtIndex:i];
[reg appendString: d.name];
}
if(gFilm.directorList.count == 0)
{
regie.text = @"N/A";
}
else
{
regie.text = reg;
}
upY = regie.frame.origin.y + regie.frame.size.height + 7;
CGRect rectTitleCast = CGRectMake(upX,upY, 100, 16);
titleCast = [[UILabel alloc] initWithFrame:rectTitleCast];
titleCast.text = @"Cast:";
titleCast.numberOfLines = 1;
titleCast.font = [titleCast.font fontWithSize:12];
titleCast.textColor = [UIColor colorWithRed:255/255.0f green:160/255.0f blue:8/255.0f alpha:1];
CGRect rectCast = titleCast.frame;
rectCast.origin.x += 40;
rectCast.size.width = self.view.frame.size.width - _detailScroll.frame.origin.x - rectCast.origin.x - upX;;
cast = [[UILabel alloc]initWithFrame:rectCast];
cast.numberOfLines = 0;
cast.font = [cast.font fontWithSize:12];
cast.textColor = [UIColor whiteColor];
NSMutableString* castStr = [[NSMutableString alloc]init];
for(int i = 0; i < gFilm.castList.count; i++)
{
Cast* c = [gFilm.castList objectAtIndex:i];
[castStr appendString: c.name];
if([c.role length] != 0)
{
[castStr appendString: @" : "];
[castStr appendString: c.role];
}
if(i != gFilm.castList.count - 1)
{
//_lblCast.numberOfLines +=1;
[castStr appendString:@"\n"];
}
}
if(gFilm.castList.count == 0)
{
cast.text = @"N/A";
}
else
{
cast.text = castStr;
}
//Customize height of label to fit content...
CGSize size = [cast.text sizeWithFont:cast.font
constrainedToSize:CGSizeMake(cast.frame.size.width, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
CGRect labelFrame = cast.frame;
labelFrame.size.height = size.height;
cast.frame = labelFrame;
upY = cast.frame.origin.y + cast.frame.size.height + 7;
CGRect rectTitlePlot = CGRectMake(upX, upY, 100, 16);
titlePlot = [[UILabel alloc]initWithFrame:rectTitlePlot];
titlePlot.numberOfLines = 1;
titlePlot.font = [titlePlot.font fontWithSize:12];
titlePlot.textColor = [UIColor colorWithRed:255/255.0f green:160/255.0f blue:8/255.0f alpha:1];
titlePlot.text = @"Plot:";
CGRect rectPlot = titlePlot.frame;
rectPlot.origin.x += 40;
rectPlot.size.width = self.view.frame.size.width - _detailScroll.frame.origin.x - rectPlot.origin.x - upX;
plot = [[UILabel alloc] initWithFrame:rectPlot];
plot.font = [plot.font fontWithSize:12];
plot.textColor = [UIColor whiteColor];
plot.numberOfLines = 0;
plot.textAlignment = NSTextAlignmentJustified;
if([gFilm.plot length] == 0)
{
plot.text = @"N/A";
}
else
{
plot.text = gFilm.plot;
}
CGSize plotsize = [plot.text sizeWithFont:plot.font
constrainedToSize:CGSizeMake(plot.frame.size.width, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
CGRect plotlabelFrame = plot.frame;
plotlabelFrame.size.height = plotsize.height;
plot.frame = plotlabelFrame;
CGSize checkWidth =[gFilm.filmTitle sizeWithFont:_lblTitel.font];
if(checkWidth.width > _lblTitel.frame.size.width)
{
CGFloat temp = titleFontSize - 4.0;
_lblTitel.font = [_lblTitel.font fontWithSize:temp];
}
else
{
_lblTitel.font = [_lblTitel.font fontWithSize:titleFontSize];
}
_lblTitel.text = gFilm.filmTitle;
NSMutableString* datNP = [[NSMutableString alloc]init];
GTimePerformance* nextPerf = gFilm.firstPerformance;
if([nextPerf.date length] != 0 && [nextPerf.performanceTime length] != 0)
{
[datNP appendString: nextPerf.date];
[datNP appendString:@" - "];
[datNP appendString:nextPerf.performanceTime];
}
else
{
datNP = @"N/A";
}
nextPerformance.text = datNP;
CGFloat contentWidth = self.view.frame.size.width - (2*upX);
CGFloat contentHeight = upY + plot.frame.size.height + 7;
contentSize = CGSizeMake(contentWidth, contentHeight);
[_detailScroll setContentSize:CGSizeMake(contentWidth, contentHeight)];
[_detailScroll setScrollEnabled:YES];
//Adding labels to scrollview..
[_detailScroll addSubview:titleRegie];
[_detailScroll addSubview:regie];
[_detailScroll addSubview:titleCast];
[_detailScroll addSubview:cast];
[_detailScroll addSubview:titlePlot];
[_detailScroll addSubview:plot];
}
直到那时没问题:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segueName isEqualToString: @"showDetail"])
{
DetailViewController* dvc = (DetailViewController*)[segue destinationViewController];
[dvc setMovie:[_coverFlowViewController getCurrentMovie]];
}
}
当我按下此视图并返回时,滚动视图不会滚动到最底部。