【问题标题】:How to redraw a view in coco-touch iOS?如何在 coco-touch iOS 中重绘视图?
【发布时间】:2012-06-24 08:14:59
【问题描述】:

我正在 cocoatouch 下使用 x-code 编程。

我在 [self.view addSubview:test]; 的 ViewDidLoad 函数中添加了很多 UIImageViews。

如果web上的信息发生变化,UI上的UIImageViews应该被其他的替换(删除原来的,添加新的)。有什么典型的方法吗?

如何重绘视图?如何移除已经被 addSubView 方法加载的 UIImageViews。

非常感谢!

【问题讨论】:

  • 你想重绘你的视图,还是改变视图层次?
  • 改变视图层次,因为点击 UIImageView 时的一些动作也改变了。

标签: ios cocoa-touch uiimageview addsubview


【解决方案1】:

根据 Apple 的 UIView 文档,您应该使用 setNeedsDisplay

【讨论】:

    【解决方案2】:

    将您的UIImageViews 存储在一个数组中。这样,您以后可以轻松访问它们以将它们从您的视图中删除。

    在 MyViewController.h 中:

    @interface ResultsViewController {
        NSMutableArray *myImageViews;
    }
    

    在 MyViewController.m 中:

    - (void)viewDidLoad {
        // Initialize image views
        UIImageView *imageView = ...
        [self.view addSubview:imageView]; 
        [myImageViews addObject:imageView];
    }
    
    // Some action is called
    - (void)somethingHappens {
        // Remove imageViews
        for (UIImageView *imageView in myImageViews) {
            [imageView removeFromSuperView];
        }
    
        // Empty myImageViews array
        [myImageViews removeAllObjects];
    
        // Create new imageViews
        UIImageView *imageView = ...
        [myImageViews addObject:imageView];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-01
      相关资源
      最近更新 更多