0

我正在制作一个应用程序,其中我需要使用Objective-C中的按钮单击在视图之间传递数据。

我已经创建了ViewController.m传递DetailController.m获取......

视图控制器.m:

   - (IBAction)btnSubmit:(id)sender {

     NSString *name = [txtName text];

     DetailController *view2 = [[[DetailController alloc] 
     initWithNibName:nil  bundle:nil] autorelease];
     [self presentViewController:view2 animated:NO completion:NULL];

      }

细节控制器.m

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

        lblResult.text = [self.detailItem description];
      }

我不明白为什么我无法将名称值传递给另一个视图

4

2 回答 2

6

忘了添加这一行:

view2.detailItem = 名称;

      (IBAction)btnSubmit:(id)sender {

         NSString *name = [txtName text];

            DetailController *view2 = [[[DetailController alloc] 
            initWithNibName:nil bundle:nil] autorelease];
            view2.detailItem = name;
            [self presentViewController:view2 animated:NO completion:NULL];

  }
于 2013-04-17T05:57:06.523 回答
1
DetailController *view2 = [[[DetailController alloc] 
     initWithNibName:nil  bundle:nil] autorelease];
view2.detailItem = self.yourValue;    
[self presentViewController:view2 animated:NO completion:NULL];
于 2013-04-17T05:58:24.670 回答