0

我在 MasterViewController.h 中声明了一个字符串作为属性

    @property (nonatomic , readwrite) NSString *theString;

这是我的 prepareForSegue 方法

     - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
      if ([[segue identifier] isEqualToString:@"showDetail"]) {

    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    NSString *string = [feeds[indexPath.row] objectForKey: @"link"];
   [[segue destinationViewController] setTheString:string];

  //UITextField *dest = [segue destinationViewController];
  //dest.theString = string;
}

}

DetailViewController.hi 为 textView 创建了一个出口

    @interface APPDetailViewController : UIViewController
    @property (weak, nonatomic) IBOutlet UITextView *textView;

现在,在实现中要编写什么代码,以便我可以将 MasterViewController 中的“theString”显示到 DetailViewController 中的 textField 中?

4

2 回答 2

1

DetailViewController.h

@property (nonatomic , strong) NSString *myString; //Do this

主视图控制器.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"showDetail"]) {

        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        NSString *string = [feeds[indexPath.row] objectForKey: @"link"];

        //Do this
        APPDetailViewController *myController = (APPDetailViewController*)segue.destinationViewController;
        myController.myString = string;
    }
}

试试这个方法。

于 2013-07-27T06:14:29.350 回答
1

1-里面应该theString有财产DetailViewController。(可选,请参阅下面的步骤 3)

2 - 要编译和运行上述代码,您还必须destinationViewController转换为DetailViewController.

像这样:

DetailViewController * destVC = (DetailViewController *) [segue destinationViewController];

3 -

destVC.theString = string;

或者,没有theStringinside DetailViewController,您可以这样做:

destVC.textView.text = string;
于 2013-07-27T06:15:22.670 回答