0

こんにちは私は、サーバーから複数の画像をロードするプロジェクトを作成しています。カウントとコメント数のようなものと、画像を気に入るボタンがあります。PageControl のような Slider Controller を使用して個々の画像を表示しています。

これはビューを表示するための私のコードです

-(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 Buttonをクリックすると、ボタンの画像といいねの数を変更する必要があります。この方法でボタン画像を変更できます

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

しかし、 Label の Like カウントを変更するにはどうすればよいですか? View の特定のラベルにアクセスするにはどうすればよいですか? タグを割り当てましたが、割り当てる方法がわかりません。写真がネットワーク(リモートサーバー)から読み込まれているため、スライダー全体をリロードしたくありません。御時間ありがとうございます。

4

1 に答える 1

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.";
}
于 2013-01-21T14:22:07.470 に答える