【问题标题】:Xcode - UILabel is not changing value on viewDidAppearXcode - UILabel 没有改变 viewDidAppear 的值
【发布时间】:2011-01-12 14:06:41
【问题描述】:

大家好,我正在创建一个 iPhone 应用程序。它使用 uitableview 并转到详细视图。

现在在详细视图上,我有一个滚动视图,所有数据 (XML) 都可以正常输入,每次都没有问题。

我的滚动视图中的 UILabel 确实会使用正确的数据进行更新,但是,它们会不断在彼此之上添加子视图以不断添加标签,这一切看起来都非常庞杂。

我已尽一切努力尝试删除子视图,例如:

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

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

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

任何可能对您有所帮助的网站的指示将不胜感激。

谢谢!

这是我在控制器中加载所有滚动视图和标签的内容:

- (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];

}

【问题讨论】:

  • 第一次好看吗?
  • 是的,第一次完美运行,但之后每次都像不断添加子视图一样。

标签: xcode uiscrollview uilabel addsubview viewdidappear


【解决方案1】:

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

如果你这样做是

-(void) viewDidLoad;

改为。

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

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

并在你的头文件中定义它:

UIScrollView *scrollView;

【讨论】:

    猜你喜欢
    • 2014-10-10
    • 2021-02-02
    • 1970-01-01
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    相关资源
    最近更新 更多