我有一个包含webview的滚动视图,webview正在显示来自xml的内容。例如,我有10页。所以,如果想要去特定的页面我应该怎么去那个页面
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*mytitle=@"Rask og grønn";
title = [title stringByReplacingOccurrencesOfString:@"\n" withString:@""];
title = [title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString*mytitle1=@"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]];
答案 0 :(得分:14)
试试这个:
- (void) viewDidLoad // Or any other method
{
[myScroll scrollRectToVisible:CGRectMake(320*pageNumber, 0, 320 , 240) animated:NO];
//320 is a width of my page,you have to replace it with your page's width
[self.view addSubview:myScroll];
}
希望这可以帮助你..