如何更新mainView的子视图中的数据

时间:2013-09-09 13:38:30

标签: ios uiview uiviewcontroller

大家好! 问题是“如何更新子视图数据?” 我设法将子视图添加到mainView中,如下所示:

        currenWeatherView.clipsToBounds = NO;
    currenWeatherView.layer.cornerRadius = 10.0;

    CGRect view1Hrame;
    view1Hrame.origin.x = 230*i;
    view1Hrame.origin.y = 0;
    view1Hrame.size = self.currenWeatherView.frame.size;

    weatherViewController *view1 = [[weatherViewController alloc] initWithForecast:[[Forecast alloc] initWithForecastInSelectedCity: theCity]]; 

    [view1.view setFrame: view1Hrame];

    [currenWeatherView addSubview: view1.view];

然后我想改变这样的数据

        for (weatherViewController *theView in weatherViewControllerArray) {
        [theView.self labelWeekTapped:2];

但是视图只是一个视图而不是类实例((

请帮忙。

1 个答案:

答案 0 :(得分:0)

在viewcontroller .m文件中声明私有属性:

@interface YourViewController ()

@property (nonatomic, strong)  weatherViewController *weatherViewController; 

@end

然后为控制器顶部指定属性:

currenWeatherView.clipsToBounds = NO;
currenWeatherView.layer.cornerRadius = 10.0;

CGRect view1Hrame;
view1Hrame.origin.x = 230*i;
view1Hrame.origin.y = 0;
view1Hrame.size = self.currenWeatherView.frame.size;

self.weatherViewController = [[weatherViewController alloc] initWithForecast:[[Forecast alloc] initWithForecastInSelectedCity: theCity]]; 

[self.weatherViewController.view setFrame: view1Hrame];

[currenWeatherView addSubview: self.weatherViewController.view];

现在在您需要更新的代码中只需调用:

[self.weatherViewController labelWeekTapped:2];

只是旁注,在Objective-C类中应始终以大写字母开头,因此weatherViewController应为WeatherViewController

然后该属性应始终以非大写字母开头。