ChildViewController在创建后无法修改其UI

时间:2014-02-17 12:46:01

标签: ios

我有一个视图控制器,它被添加为子视图控制器。问题是在子控制器创建其视图后,我无法修改它。 它正确加载所有内容,但是当我想在单击按钮(textfield.hidden = YES)时隐藏文本字段时,没有任何反应!

这是我的loadView:

-(void)loadView {
      self.waitingPopup = [[WaitingPopupViewController alloc]initWithLabel:@"loading salon"];
    self.view=[[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];

//    self.view.frame=CGRectMake(0, -20, self.view.frame.size.width, self.view.frame.size.height);
    scrollableTable=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    scrollableTable.delegate=self;
    scrollableTable.dataSource=self;

    [self.view addSubview:scrollableTable];

    headerHolder=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-44)];
    //creating and adding backgroundImage view container and setting the image
   // saloonHomeImage.backgroundColor = [UIColor grayColor];
    saloonHomeImage.frame=CGRectMake(self.view.frame.origin.x, 0, self.view.frame.size.width, self.view.frame.size.height);
    saloonHomeImage.contentMode = UIViewContentModeScaleAspectFill;
    //[saloonHomeImage setBackgroundColor:[UIColor redColor]];
    [headerHolder setBackgroundColor:[UIColor grayColor]];
    [headerHolder addSubview:saloonHomeImage];

    //creating and adding saloonheader label
    saloonLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 32, self.view.frame.size.width, 48)];
    saloonLabel.text=@"";
    saloonLabel.textAlignment=NSTextAlignmentCenter;
    [saloonLabel setTextColor:[UIColor whiteColor]];
    [saloonLabel setFont:[UIFont fontWithName:@"vevey" size:48]];
    [headerHolder addSubview:saloonLabel];

    //creating and adding book appointment button
    UIButton *bookAppointmentButton=[UIButton buttonWithType:UIButtonTypeSystem];
    NSLog(@"%f", self.view.frame.size.height-97.5);
    bookAppointmentButton.frame=CGRectMake(self.view.frame.origin.x, self.view.frame.size.height-97.5, 216, 53);
    [bookAppointmentButton setBackgroundImage:[UIImage imageNamed:@"bg-left.png"] forState:UIControlStateNormal];
    [bookAppointmentButton setTitle:@"BOOK APPOINTMENT" forState:UIControlStateNormal];
    [bookAppointmentButton addTarget:self action:@selector(bookAppointmentAction) forControlEvents:UIControlEventTouchUpInside];
    [bookAppointmentButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [headerHolder addSubview:bookAppointmentButton];


    UIButton *callButton=[UIButton buttonWithType:UIButtonTypeSystem];
    callButton.frame=CGRectMake(216, self.view.frame.size.height-97.5, self.view.frame.size.width-216, 53);
    [callButton setBackgroundImage:[UIImage imageNamed:@"bg-right.png"] forState:UIControlStateNormal];
    [callButton addTarget:self action:@selector(callButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [callButton setTitle:@"CALL" forState:UIControlStateNormal];
    [callButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [headerHolder addSubview:callButton];
    [self getSalonDetails];

    loading=[[UIImageView alloc] init];
    loading.frame=CGRectMake(130,200,40,36);
    [loading setBackgroundColor:[UIColor clearColor]];
    loading.animationImages = [NSArray arrayWithObjects:
                               [UIImage imageNamed:@"spinner-1.png"],
                               [UIImage imageNamed:@"spinner-2.png"],
                               [UIImage imageNamed:@"spinner-3.png"],
                               [UIImage imageNamed:@"spinner-4.png"],
                               [UIImage imageNamed:@"spinner-5.png"],
                               [UIImage imageNamed:@"spinner-6.png"],
                               [UIImage imageNamed:@"spinner-7.png"],
                               [UIImage imageNamed:@"spinner-8.png"],[UIImage imageNamed:@"spinner-9.png"],nil];

    loading.animationDuration = 1.0f;
    loading.animationRepeatCount = 0;
    [loading startAnimating];
    [self.view addSubview:loading];

    loadingText = [[UILabel alloc]initWithFrame:CGRectMake(90, 240, 200, 40)];
    loadingText.text = @"loading salon";
    [loadingText setFont:GOTHIC_FONT(22)];
    [loadingText setTextColor:[UIColor whiteColor]];
    [self.view addSubview:loadingText];


    articles=[Model getArticles];
}

- (void) getSalonDetails{

    [[MyDataModel sharedDataModel] getSalonDetails];
}

这是委托方法,它试图设置一些隐藏的字段。 NSURLSession调用成功完成后,将调用此委托。控件按日志来到此处,但没有任何内容被隐藏。当我添加断点并检查字段时,每个对象都显示为nil。如果这个类被用作主视图控制器,我发现一切正常。在使它成为子视图时,没有任何作用。

-(void)salonDetailsRecievedDelegate:(BOOL)success andStatusCode:(int)statusCode{

    [loading stopAnimating];
    self.loading.hidden = YES;
    self.loadingText.hidden = YES;
    saloonLabel.text = @"this is texT";
    if(success){
        //
    }
}

1 个答案:

答案 0 :(得分:0)

我认为这里不会从主线程中调用salonDetailsRecievedDelegate,请尝试以下任何一种方法:

1)在模型的主线程中调用它,如下所示:

dispatch_async(dispatch_get_main_queue(), ^{
  [self.delegate salonDetailsRecievedDelegate:success andStatusCode:status];
});

2)改变其实施如下:

-(void)salonDetailsRecievedDelegate:(BOOL)success andStatusCode:(int)statusCode{

    dispatch_async(dispatch_get_main_queue(), ^{
      [loading stopAnimating];
      self.loading.hidden = YES;
      self.loadingText.hidden = YES;
      saloonLabel.text = @"this is texT";
      if(success){
          //
      }
    });

}