0

IBOutlet の UILabel を更新しようとしていますが、何らかの理由でコンテンツが更新されません。最初に、非同期で jsonResponse を実行するモデルからコンテンツがロードされます。ただし、setNeedsDisplay を呼び出しているレイアウトを更新するために、コンテンツがそこにあるときにデリゲートを設定しました。

ここで何か助けていただければ幸いです。

ありがとう。

以下のコード:

@interface pd ()

@property (nonatomic,retain) NSDictionary *pD;
@property (nonatomic, retain) pd_model *pdModel;

@end

@implementation pd

@synthesize pD = _pD, pdModel;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil :(NSDictionary*)pD {

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {
        // Custom initialization
        self.productDetails = [[NSDictionary alloc] initWithDictionary:pD];
        self.pdModel = [[ProductDetails_Model alloc] init:pD];
        self.pdModel.delegate = self;
        NSLog(@"%@",[self.pD description]);
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    [scrollView setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:scrollView];
    scrollView.showsHorizontalScrollIndicator = YES;
    scrollView.scrollEnabled = YES;

    // Do any additional setup after loading the view from its nib.

    productRecCarousel = [[iCarousel alloc] initWithFrame:CGRectMake(0.0f, scrollView.contentSize.height, 320.0f, 100.0)];
    productRecCarousel.delegate = self;

    [scrollView addSubview:productRecCarousel];

    [self addProductDescription];
    NSLog(@"%@",[self.pdModel responseCode]);
    [soldBy setText:[self.pdModel responseCode]];
    //[soldBy setText:@"1"];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark
#pragma mark CarouselDelegate methods
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel {

    return 1;
}

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel {

    return 1;
}

- (UIView*)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {

    return [[UIView alloc] init];
}

- (CGFloat)carouselItemWidth:(iCarousel *)carousel {
    //usually this should be slightly wider than the item views
    return 150;
}

- (CATransform3D)carousel:(iCarousel *)_carousel transformForItemView:(UIView *)view withOffset:(CGFloat)offset {
    //implement 'flip3D' style carousel

    //set opacity based on distance from camera
    view.alpha = 1.0 - fminf(fmaxf(offset, 0.0), 1.0);

    //do 3d transform
    CATransform3D transform = CATransform3DIdentity;
    transform.m34 = _carousel.perspective;
    transform = CATransform3DRotate(transform, M_PI / 8.0, 0, 1.0, 0);
    return CATransform3DTranslate(transform, 0.0, 0.0, offset * _carousel.itemWidth);
}

- (void)addProductDescription {

    NSLog(@"%f",addProductDetails.frame.size.height);
    addProductDetails.frame = CGRectMake(0.0f, productRecCarousel.frame.size.height, addProductDetails.frame.size.width, addProductDetails.frame.size.height);
    [scrollView addSubview:addProductDetails];


}

- (void)updateTheLayout {

    //[self.view setNeedsDisplay];
   //This is where I get the delegate called once the model is being updated. I tried scrollView and self.view setNeedsDisplay and setNeedsLayout but the IBoutlet never gets updated which is in "ViewDidLoad as assigned as" : [soldBy setText:[self.pdModel responseCode]];

}

ありがとう。

4

2 に答える 2

4

そのため、まだ準備ができていないため、からではなく[soldBy setText:[self.pdModel responseCode]];updateTheLayoutから呼び出す必要があります。viewDidLoadそして、必ずメイン スレッドから UI 要素を更新してください。

于 2012-10-15T22:54:01.713 に答える
2

[soldBy setText:[self.pdModel responseCode]];メソッドではなく、コールバックで呼び出す必要がありますviewDidLoad

于 2012-10-15T22:52:54.483 に答える