0

今天是个好日子!问题是“如何更新 subViews 数据?” 我设法将子视图添加到 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];

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

请帮忙。

4

1 回答 1

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.

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

于 2013-09-09T13:56:09.717 回答