从view1中修改view2的UItextField

在ViewController中,修改SecondViewControllerUITextView.text

如果它是NSString类型可以这么修改:

SVC.string = @"test";

出现两个问题:

  • messageBox.text没有修改
  • SVC.messageBox.text 返回(null)

ViewController.m:

 SecondViewController *SVC = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
 SVC.messageBox.text = @"changed";
 NSLog(@"SVC: %@", SVC.messageBox.text); // result = (null)

 [self presentViewController:SVC animated:YES completion:NULL];

SecondViewController.h:

#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController

@property (nonatomic) IBOutlet UITextView *messageBox;


@end

SecondViewController.m:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    self.messageBox.text = @"first";
}

建议楼主 断点一下试试 设置messageBox 的是你要设置的控件么 并且是否为空。ios中对空对象发送信息 不会发生异常