开发者

UIScrollView to jump particular page

开发者 https://www.devze.com 2023-03-16 15:09 出处:网络
I have a scroll view containing webview and webview is displaying content from xml. for e.g i have 10 pages . so if a want to go particular page how should i go to that page

I have a scroll view containing webview and webview is displaying content from xml. for e.g i have 10 pages . so if a want to go particular page how should i go to that page

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) {

        开发者_StackOverflow社区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:@"&aring;" withString:@"å"];
    description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    description = [description stringByReplacingOccurrencesOfString:@"&oslash;" withString:@"ø"];
    description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];


    description = [description stringByReplacingOccurrencesOfString:@"&aelig;" withString:@"æ"];
    description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];


    description = [description stringByReplacingOccurrencesOfString:@"&AElig;" withString:@"Æ"];
    description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];


    description = [description stringByReplacingOccurrencesOfString:@"&Oslash;" withString:@"Ø"];
    description = [description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];


    description = [description stringByReplacingOccurrencesOfString:@"&Aring" 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]];


try this :

- (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];        
}

hope this helps you..

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号