我有一個包含webview和webview的滾動視圖顯示來自xml的內容。例如我有10頁。所以如果一個想要去特定頁面我應該怎麼去那個頁面UIScrollView跳轉特定頁面
int j = myindex;
int k=0;
for (int i=0; i < [appDelegate.books count]; i++) {
if (j>i) {
// //j++;
continue;
}
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * k;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView*subView=[[UIView alloc ]initWithFrame:frame];
//subView.backgroundColor=[appDelegate.books objectAtIndex:i];
[self.scrollView addSubview:subView];
CGRect myframe=CGRectMake(8, 16, 371, 242);
UIImageView*imageView=[[UIImageView alloc] initWithFrame:myframe];
Book*aBook=[appDelegate.books objectAtIndex:i];
NSString*myimage=aBook.mainimgurl;
myimage = [myimage stringByReplacingOccurrencesOfString:@"\n" withString:@""];
myimage = [myimage stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:myimage]]];
j++;
imageView.image=image;
CGRect mywebframe=CGRectMake(0, 30, 768, 876);
UIWebView*webView=[[UIWebView alloc] initWithFrame:mywebframe];
/*NSString*title=aBook.title;
NSString*[email protected]"Rask og grønn";
title = [title stringByReplacingOccurrencesOfString:@"\n" withString:@""];
title = [title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString*[email protected]"Fortidsklimaet på Svalbard";
if ([title isEqualToString:mytitle ] || [title isEqualToString:mytitle1]) {
htmlString=aBook.magazinenumberdescription;
}*/
if (aBook.fulltext==nil) {
htmlString=aBook.magazinenumberdescription;
}
else {
htmlString=aBook.fulltext;
}
//NSString*htmlString=aBook.description;
[webView loadHTMLString:htmlString baseURL:nil];
[subView addSubview:webView];
CGRect myframe1=CGRectMake(387, 16, 363, 292);
UITextView*textView=[[UITextView alloc] initWithFrame:myframe1];
textView.font=[UIFont fontWithName:@"Times New Roman" size:16];
NSString*description=aBook.description;
description = [description stringByReplacingOccurrencesOfString:@"\n" withString:@""];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
description = [description stringByReplacingOccurrencesOfString:@"å" withString:@"å"];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
description = [description stringByReplacingOccurrencesOfString:@"ø" withString:@"ø"];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
description = [description stringByReplacingOccurrencesOfString:@"æ" withString:@"æ"];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
description = [description stringByReplacingOccurrencesOfString:@"Æ" withString:@"Æ"];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
description = [description stringByReplacingOccurrencesOfString:@"Ø" withString:@"Ø"];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
description = [description stringByReplacingOccurrencesOfString:@"Å" withString:@"Å"];
description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
k++;
textView.text=description;
// [subView addSubview:textView];
// [subView addSubview:imageView];
}
//NSInteger numberofPages=10-j;
NSInteger numberofPages=[appDelegate.books count];
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * numberofPages, self.scrollView.frame.size.height);
[pageControl setNumberOfPages:numberofPages];
[pageControl setActivePageColor:[UIColor clearColor]];
[pageControl setInactivePageColor:[UIColor clearColor]];
你有許多Web視圖中顯示爲滾動視圖頁面? – 2011-06-30 05:26:37
是的,我在循環中創建webview並將該webview添加到滾動視圖 – Ali
是否意味着您有10個Web視圖?或者一個Web視圖包含一個長頁面? – Maulik