我已将字符串声明为属性 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.h 我已经为textView
创建了一个插座 @interface APPDetailViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextView *textView;
现在,在实现中代码是什么,所以我可以在MasterViewController中将“theString”显示到DetailViewController中的textField?
答案 0 :(得分:1)
<强> DetailViewController.h 强>
@property (nonatomic , strong) NSString *myString; //Do this
<强> MasterViewController.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;
}
}
试试这种方式。
答案 1 :(得分:1)
1 - theString
内应该有DetailViewController
个属性。 (可选,请参阅下面的步骤3)
2 - 要编译和运行上述代码,您还必须将destinationViewController
强制转换为DetailViewController
。
像这样:
DetailViewController * destVC = (DetailViewController *) [segue destinationViewController];
3 -
destVC.theString = string;
可选地,theString
内没有DetailViewController
,您可以这样做:
destVC.textView.text = string;