2013-01-21 65 views
0

嗨我創建一個項目,其中多個圖像從服務器加載有一些像計數和評論計數和一個按鈕喜歡的形象。我使用像PageControl這樣的滑塊控制器來顯示單個圖像。如何訪問pageControl viewController的特定視圖?

這是我顯示的立即查看

-(UIView*)reloadView:(DPSliderView *)sliderView viewAtIndex:(NSUInteger)idx 
{ 
    _loading_view.hidden=TRUE; 
    if (idx < [photos count]) { 
     NSDictionary *item = [photos objectAtIndex:idx]; 

     PhotoView *v = [[PhotoView alloc] init]; 
     v.photoIndex = idx; 
     v.imageView.imageURL = [DPAPI urlForPhoto:item[@"photo_220x220"]]; 
     NSString *placename1 = [item valueForKeyPath:@"spotting.item.name"]; 
     NSString *firstCapChar1 = [[placename1 substringToIndex:1] capitalizedString]; 
     NSString *cappedString1 = [placename1 stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstCapChar1]; 
     v.spotNameLabel.text = cappedString1; 

     NSString *placename = [item valueForKeyPath:@"spotting.place.name"]; 
     NSString *firstCapChar = [[placename substringToIndex:1] capitalizedString]; 
     NSString *cappedString = [placename stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstCapChar]; 
     NSString *place1=[NSString stringWithFormat:@"%@",cappedString]; 
     NSString *address=[NSString stringWithFormat:@"%@",[item valueForKeyPath:@"spotting.place.address"]]; 

     NSString *location_str3 = [NSString stringWithFormat:@"@ %@, %@",place1,address]; 
     int cap_len=[place1 length]; 
     int address_lenth=[address length]; 

     ZMutableAttributedString *str = [[ZMutableAttributedString alloc] initWithString:location_str3 
                       attributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                          [[FontManager sharedManager] zFontWithName:@"Lucida Grande" pointSize:12], 
                          ZFontAttributeName, 
                          nil]]; 
     [str addAttribute:ZFontAttributeName value:[[FontManager sharedManager] zFontWithName:@"Lucida Grande" pointSize:12] range:NSMakeRange(0, cap_len+3)]; 

     [str addAttribute:ZForegroundColorAttributeName value:[UIColor colorWithRed:241/255.0f green:73.0/255.0f blue:2.0/255.0f alpha:1.0]range:NSMakeRange(0, cap_len+3)]; 

     [str addAttribute:ZForegroundColorAttributeName value:[UIColor colorWithRed:128.0/255.0f green:121.0/255.0f blue:98.0/255.0f alpha:1.0]range:NSMakeRange(cap_len+4, address_lenth)]; 

     v.placefontlabel.zAttributedText=str; 

     v.likesCountLabel.text = [NSString stringWithFormat:@"%i", [item[@"likes_count"] intValue]]; 
     if ([_device_lang_str isEqualToString:@"es"]) 
     { 
      v.shightingsLabel.text = [NSString stringWithFormat:NSLocalizedString(@"%i Vistas", nil), [item[@"sightings_count"] intValue]]; 
     } 
     else 
     { 
      v.shightingsLabel.text = [NSString stringWithFormat:NSLocalizedString(@"%i Sightings", nil), [item[@"sightings_count"] intValue]]; 
     } 
     if ([nolocationstr isEqualToString:@"YES"]) 
     { 
      v.distanceLabel.text =[NSString stringWithFormat:@"%.2f km", [item[@"distance"] floatValue]]; 
     } 
     else 
     { 
      CLLocation *location1 = [[CLLocation alloc] initWithLatitude:[[item valueForKeyPath:@"spotting.place.lat"]floatValue] longitude:[[item valueForKeyPath:@"spotting.place.lng"] floatValue]]; 
      CLLocation *location2 = [[CLLocation alloc] initWithLatitude:[_explore_lat_str floatValue] longitude:[_explore_lng_str floatValue]]; 
      NSString *lat_laong=[NSString stringWithFormat:@"%f",[location1 distanceFromLocation:location2]]; 
      int km=[lat_laong floatValue]*0.001; 
      NSString *distancestr=[NSString stringWithFormat:@"%d km",km]; 
      float dist=[distancestr floatValue]; 
      v.distanceLabel.text = [NSString stringWithFormat:@"%.2f km", dist]; 
     } 

     if (![item[@"likes"] boolValue]) { 
      v.likeButton.enabled = YES; 
      v.likeButton.tag = idx; 
      [v.likeButton setImage:[UIImage imageNamed:@"like_new.png"] forState:UIControlStateNormal]; 
      [v.likeButton addTarget:self action:@selector(likeAction:) forControlEvents:UIControlEventTouchUpInside]; 
     } 
     else 
     { 
      v.likeButton.tag = idx; 
      [v.likeButton setImage:[UIImage imageNamed:@"like_new1.png"] forState:UIControlStateNormal]; 
     } 

     NSArray *guides = item[@"guides"]; 
     if ([guides count] > 0) { 
      NSString *guideType = [[guides objectAtIndex:0] valueForKey:@"type"]; 
      UIImage *guidesIcon = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png", guideType]]; 
      v.guideButton.hidden = NO; 
      v.guideButton.tag = idx; 
      [v.guideButton setImage:guidesIcon forState:UIControlStateNormal]; 
      [v.guideButton addTarget:self action:@selector(guideAction:) forControlEvents:UIControlEventTouchUpInside]; 
     } 
     v.shareButton.tag = idx; 
     [v.shareButton addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside]; 

     UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(photoTapGesture:)]; 
     [v addGestureRecognizer:tapGesture]; 
     [tapGesture release]; 

     return [v autorelease]; 
    } else { 
     UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sc_img.png"]]; 
     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
     indicator.center = CGPointMake(CGRectGetMidX(iv.bounds), 110); 
     [indicator startAnimating]; 
     [iv addSubview:indicator]; 
     [indicator release]; 
     return [iv autorelease]; 
    } 


} 

我的問題是代碼:

如果我將點擊Like按鈕,然後我不得不更改按鈕圖像,以及像計數。我可以通過此方法更改按鈕圖像

[sender setImage:[UIImage ImageNamed:@"image.png"]]; 

但是,如何更改標籤的Like計數?我如何訪問視圖的特定標籤?我已經分配了標籤但是,我不知道如何分配它。我不想在從網絡(遠程服務器)加載照片時重新加載整個滑塊。謝謝你的時間。

回答

0

只要保留對標籤的引用並更新即可。

// @interface 
@property (nonatomic, strong) UILabel *myLabel; 

// @implementation 
_myLabel.text = @"Whatever."; 

如果你有多個標籤,當你創建你的意見

newView.tag = sequenceNumber +100; 

,然後更新設置的標籤

-(void)updateLabelWithTag:(NSInteger)tag { 
    UILabel *label = (UILabel*) [self.scrollView viewWithTag:tag]; 
    label.text = @"Whatever."; 
} 
相關問題