0

我有两个类 uiviewcontroller 和 uiview。我有一个视图控制器。里面我有uiview。在 uiview 我有文本字段,当我写一个文本并单击完成时,我需要刷新 uiviewcontroller。

我在 uiview 类中尝试了这个:

  -(IBAction)textFieldReturn:(id)sender
{

      ViewController *vc = [[ViewController alloc] init];
        [vc viewDidLoad];
}

我需要刷新,就像您单击按钮并打开视图控制器一样。

4

1 回答 1

0

I am guessing you mean that you want to "refresh" the view, not the view controller. To do that simply call [self setNeedsDisplay] from the view, or [self.view setNeedsDisplay] from the view controller. Also make sure that the textfield is a subview of the uiview. Either do that in the nib file or in code by calling [self addSubview: (textfield here)].

Also, if you want to access the view controller from the view you will need to create an IBOutlet, simply allocating a new ViewController object within the view does not mean that the created view controller controls the view. Hopefully that makes sense. I'd recommend going through some ios starter tutorials as well. Just google that there are a lot.

于 2012-09-07T20:18:51.910 回答