2012-01-13 13 views
0

私はスクロールビューを使用して画像ビューで画像を読み込み、次に画像を保存したいのですが、コレクションに保存します。私は、画像を保存するときだから、常にPAGENUMBER = 1が唯一の私が今までに何ページときにそれを追加することを望んとるだけであなたは、スクロールビューのページングを有効にする必要がありScrollViewで読み込まれたデータベースに画像を保存するには

 -(void) loadNews{ 



     NSURL*myurl=url; 

    myurl = [myurl stringByReplacingOccurrencesOfString:@"\n" withString:@""]; 
    myurl = [myurl stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 



    NSURL*urlloaded= [[NSURL alloc]initWithString:myurl]; 


    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:urlloaded]; 





    //Initialize the delegate. 

    RowTwoParser *parser = [[RowTwoParser alloc] initXMLParser]; 

    //Set delegate 

    [xmlParser setDelegate:parser]; 
    BOOL success = [xmlParser parse]; 

    if(success) 

    NSLog(@"No Errors"); 

    else 

    NSLog(@"Error Error Error!!!"); 
    int k=0; 
    for (int i=0; i < [appDelegate.articles count]; i++) { 

    currentIndex=i; 
    CGRect frame; 
    frame.origin.x = self.scrollView.frame.size.width * i; 
    frame.origin.y = 0; 
    frame.size = self.scrollView.frame.size; 
    UIView*subView=[[UIView alloc ]initWithFrame:frame]; 
    [self.scrollView addSubview:subView]; 
    RowTwo*aRowTwo=[appDelegate.articles objectAtIndex:i]; 



     CGRect mywebframe=CGRectMake(20, 60, 728, 800); 

    UIImageView*imageView=[[UIImageView alloc] initWithFrame:mywebframe]; 


    NSString*thumb2=aRowTwo.image; 



     thumb2 = [thumb2 stringByReplacingOccurrencesOfString:@"\n" withString:@""]; 
     thumb2 = [thumb2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 


      NSURL *url = [NSURL URLWithString:thumb2]; 
     NSData *data = [[NSData alloc] initWithContentsOfURL:url]; 
     UIImage *image2 = [[UIImage alloc] initWithData:data]; 

     imageView.image =image2 ; 

     [subView addSubview:imageView]; 

     } 




    //NSInteger numberofPages=10-j; 
    NSInteger numberofPages=[appDelegate.articles count]; 
     self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * numberofPages, self.scrollView.frame.size.height); 
    CGRect frame; 
    //frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage; 
    frame.origin.x = self.scrollView.frame.size.width * myindex; 
     frame.origin.y = 0; 
     frame.size = self.scrollView.frame.size; 
     [self.scrollView scrollRectToVisible:frame animated:YES]; 



    [pageControl setNumberOfPages:numberofPages]; 
    [pageControl setActivePageColor:[UIColor clearColor]]; 
    [pageControl setInactivePageColor:[UIColor clearColor]]; 

    } 
    -(IBAction)addToCollectionButtonAction{ 




    GeoNewsAppDelegate *appDelegate = (GeoNewsAppDelegate *)[[UIApplication sharedApplication] delegate]; 

    // Create a Coffee Object. 
    Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:0]; 

    int pageNumber = [pageControl currentPage]; 
    NSLog(collectionImage); 


    RowTwo*aRowTwo=[appDelegate.articles objectAtIndex:pageNumber]; 




    NSString*thumb2=aRowTwo.image; 

    coffeeObj.thumb = thumb2; 
    coffeeObj.path = thumb2; 





    [appDelegate addCoffee:coffeeObj]; 



    } 

答えて

0

ナンバーワンではない他にあるページを追加し

self.scrollView.pagingEnabled = YES

+0

私はthsiのようにしましたが、もう一度pageControl.currentPageの値1を表示します –

+0

UIScrollView Pagingうまくいきません---あなたの質問は正しいですか?コードは理解できません、短いメモで各mthdを書いてください。 – vishy

+0

ページングは​​うまくいきますが、私の質問はこれがページ2にあり、コレクションにその画像を追加するために追加ボタンをクリックするということです。そのページのイメージは保存されませんが、ページ1を保存する –

関連する問題