我有一個小應用程序與一些細節控制器。詳細控制器是把滾動視圖內的Web視圖: 下面是詳細視圖控制器的代碼:滾動視圖中的Iphone Web視圖
- (void)loadScrollViewWithPage:(int)page
{
if (page < 0)
return;
if (page >= detailTotalJobs)
return;
// replace the placeholder if necessary
SearchJobDetailWebViewController *controller = [viewControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null])
{
NSLog(@"Vytvaram web controller: %d", page + 1);
if (detailJobIndex == page) {
controller = [[SearchJobDetailWebViewController alloc] initWithNibName:@"SearchJobDetailWebViewController" bundle:nil page:page url:detailExportUrl];
[viewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
} else if (detailJobIndex + 1 == page) {
controller = [[SearchJobDetailWebViewController alloc] initWithNibName:@"SearchJobDetailWebViewController" bundle:nil page:page url:detailNextExportUrl];
[viewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
} else {
[self performSelector:@selector(downloadData:) withObject:[NSNumber numberWithInt:page] afterDelay:0.1];
//[self downloadData:[NSNumber numberWithInt:page]];
controller = [[SearchJobDetailWebViewController alloc] initWithNibName:@"SearchJobDetailWebViewController" bundle:nil page:page url:nextArray.exportUrl];
[viewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}
}
// add the controller's view to the scroll view
if (controller.view.superview == nil)
{
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[scrollView addSubview:controller.view];
//NSDictionary *numberItem = [self.contentList objectAtIndex:page];
//controller.numberImage.image = [UIImage imageNamed:[numberItem valueForKey:ImageKey]];
//controller.myLabel.text = @"Test";
}
}
- (void)scrollViewDidScroll:(UIScrollView *)sender
{// 我們不不需要UIPageControl和滾動代理之間的「反饋循環」 //其中滾動事件是從用戶點擊頁面控制觸發從 //委託方法更新。當使用頁面控件時,我們使用布爾值來禁用委託邏輯。 if(pageControlUsed) //不執行任何操作 - 滾動是從頁面控件啓動的,而不是用戶拖動 返回; }
// Switch the indicator when more than 50% of the previous/next page is visible
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth/2)/pageWidth) + 1;
pageControl.currentPage = page;
NSString *detailTitleText = [NSString stringWithFormat:@"%d/%d", page + 1, detailTotalJobs];
[self setTitle:detailTitleText];
//[detailTitleText release];
// load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling)
[self loadScrollViewWithPage:page - 1];
[self loadScrollViewWithPage:page];
[self loadScrollViewWithPage:page + 1];
// A possible optimization would be to unload the views+controllers which are no longer visible
}
代碼由蘋果頁面控制的啓發。
問題是在這裏:
if (detailJobIndex == page) {
controller = [[SearchJobDetailWebViewController alloc] initWithNibName:@"SearchJobDetailWebViewController" bundle:nil page:page url:detailExportUrl];
[viewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
} else if (detailJobIndex + 1 == page) {
controller = [[SearchJobDetailWebViewController alloc] initWithNibName:@"SearchJobDetailWebViewController" bundle:nil page:page url:detailNextExportUrl];
[viewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
} else {
[self performSelector:@selector(downloadData:) withObject:[NSNumber numberWithInt:page] afterDelay:0.1];
//[self downloadData:[NSNumber numberWithInt:page]];
controller = [[SearchJobDetailWebViewController alloc] initWithNibName:@"SearchJobDetailWebViewController" bundle:nil page:page url:nextArray.exportUrl];
[viewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}
第一部分,如果工作的第二部分正確,因爲我對第一個網頁視圖和第二Web視圖的數據。
但是,如果有問題的最後一部分。當我從第二個Web視圖滾動到第三個Web視圖時,滾動視圖顯示空白頁面。下一頁正常工作。 問題在哪裏?
如果我的答案有幫助,您可以接受答案/ upvote嗎? – Oliver