我正在使用滚动视图从数组加载图像视图中的图像,然后我要保存的图像保存到集合中。因此,当我保存图像时,它总是需要pageNumber = 1只有我想要添加它时的页面只添加第一个而不是其他页面
-(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 :(得分:0)
您需要为滚动视图启用分页
self.scrollView.pagingEnabled = YES