Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 更新UIlabel的文本_Ios_Objective C_Uilabel - Fatal编程技术网

Ios 更新UIlabel的文本

Ios 更新UIlabel的文本,ios,objective-c,uilabel,Ios,Objective C,Uilabel,我有一个幻灯片,可以从数据库中收集一系列图像。每个图像都有与其关联的描述和其他属性。基本上,我想在每次加载新图像时更新UILabel的文本。我该怎么做 以下是我的工作内容: //SLIDE MENU - (void)loadVisiblePages { // First, determine which page is currently visible CGFloat pageWidth = gridView.frame.size.width; NSInteger p

我有一个幻灯片,可以从数据库中收集一系列图像。每个图像都有与其关联的描述和其他属性。基本上,我想在每次加载新图像时更新UILabel的文本。我该怎么做

以下是我的工作内容:

 //SLIDE MENU
- (void)loadVisiblePages {
    // First, determine which page is currently visible
    CGFloat pageWidth = gridView.frame.size.width;
    NSInteger page = (NSInteger)floor((gridView.contentOffset.x * 2.0f + pageWidth) / (pageWidth * 2.0f));
    //NSArray * descriptArray[20];

    // Update the page control
    pageControl.currentPage = page;

    // Work out which pages you want to load
    NSInteger firstPage = page - 1;
    NSInteger lastPage = page + 1;

    // Purge anything before the first page
    for (NSInteger i=0; i<firstPage; i++) {
        [self purgePage:i];
    }
    for (NSInteger i=firstPage; i<=lastPage; i++) {
        [self loadPage:i];
        // descriptArray[i] = selectedPhotoDesc;
    }
    for (NSInteger i=lastPage+1; i<self.pageImages.count; i++) {
        [self purgePage:i];
    }
}


- (void)loadPage:(NSInteger)page {
    NSURL* imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@/%@.jpg", host, photoPath, collection, photoNumber]];

    //get photo from server
    NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageURL];
    UIImage *image = [[UIImage alloc] initWithData: imageData];

    if (page < 0 || page >= 20) {
        return;
    }

    // Load an individual page, first checking if you've already loaded it
    UIView *pageView = [self.pageViews objectAtIndex:page];
    if ((NSNull*)pageView == [NSNull null]) {
        CGRect frame = gridView.bounds;
        frame.origin.x = frame.size.width * page;
        frame.origin.y = 0.0f;
        frame = CGRectInset(frame, 10.0f, 0.0f);
        UIImageView *newPageView = [[UIImageView alloc] initWithImage:image];
        newPageView.frame = frame;
        [gridView addSubview:newPageView];
        labelDescription.text = descriptionArray[page];
        [self.pageViews replaceObjectAtIndex:page withObject:newPageView];
    }
}

- (void)purgePage:(NSInteger)page {
    if (page < 0 || page >= self.pageImages.count) {
        // If it's outside the range of what you have to display, then do nothing
        return;
    }

// Remove a page from the scroll view and reset the container array
UIView *pageView = [self.pageViews objectAtIndex:page];
if ((NSNull*)pageView != [NSNull null]) {
    [pageView removeFromSuperview];
    [self.pageViews replaceObjectAtIndex:page withObject:[NSNull null]];
    labelDescription.text = @"";
}
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // Load the pages that are now on screen
    [self loadVisiblePages];
}
//幻灯片菜单
-(无效)加载可视页面{
//首先,确定当前可见的页面
CGFloat pageWidth=gridView.frame.size.width;
NSInteger页面=(NSInteger)楼层((gridView.contentOffset.x*2.0f+pageWidth)/(pageWidth*2.0f));
//NSArray*描述符数组[20];
//更新页面控件
pageControl.currentPage=页面;
//确定要加载的页面
NSInteger firstPage=第1页;
NSInteger lastPage=第+1页;
//清除第一页之前的任何内容

对于(NSInteger i=0;i)您可以使用与标签的
页面视图
相同的逻辑。有比此方法更好的选项,可以使用UICollectionView或UIPageViewController来简化操作。我没有注意您的代码,因为我认为您正在尝试重新发明轮子。只需使用以下库-(使用iCarouselTypeLinear)