Xcode - UILabel没有改变viewDidAppear的值

时间:2011-01-12 14:06:41

标签: xcode uiscrollview uilabel addsubview viewdidappear

嘿大家,我有一个我正在创建的iPhone应用程序。它使用了一个uitableview,并进入了详细视图。

现在在详细视图中我有一个滚动视图,所有数据(XML)都很好,每次都没有问题。

我的滚动视图中的我的UILabel会使用正确的数据进行更新,但是,他们会不断添加子视图,以便在标签后添加标签,这一切看起来都非常简洁。

我已经尝试了一切来尝试删除子视图,例如:

for(UIView *subview in [scrollView subviews]) {
 [subview removeFromSuperview];
}

[[scrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];

所以我很难过,我不知道发生了什么。有帮助吗?我一直在谷歌搜索年龄和年龄,但仍然找到不起作用的相同答案:(

非常感谢任何可能对您有所帮助的网站的方向。

谢谢!

以下是我在控制器中加载所有scrollview和标签的内容:

- (void)viewDidAppear:(BOOL)animated {

 // Create the scroll view for this view
 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
 scrollView.contentSize = CGSizeMake(320, 270);
 [scrollView setFrame:CGRectMake(0, 198, 320, 170)];

 // Do the labels for the text
 UILabel *dates = [[UILabel alloc] initWithFrame:scrollView.bounds];

 dates.textColor = [UIColor whiteColor];
 dates.font = [UIFont boldSystemFontOfSize:12];
 dates.text = round_date;
 dates.tag = 1;
 [dates setBackgroundColor:[UIColor clearColor]];
 [dates setFrame:CGRectMake(10, 10, 280, 22)];
 [scrollView addSubview:dates];
 [dates release];

 // Add the content to the main scrollview
 [self.view addSubview:scrollView];
 [scrollView release];

}

1 个答案:

答案 0 :(得分:0)

好的,原因是每次呈现视图时都会调用viewDidAppear。

如果你这样做是

-(void) viewDidLoad;

代替。

为确保您以后可以访问它们,您可能希望在UIViewController中保留对它们的引用

-(void) viewDidLoad {
    scrollView = [[UIScrollView alloc] initWithFrame];
    [self.view addSubview:scrollView];
}

并使用以下命令在头文件中定义:

UIScrollView *scrollView;