当我选择一个新的 viewController 时,a 想传递一个参数,让我们说“turnId”给一个新的ViewController
. 我知道我可以在prepareForSegue
方法中做到这一点,但是如何将参数传递给prepareForSegue
方法本身?我怎样才能从发件人那里得到这个?发件人是didSelectRowAtIndexPath
,但该值不在单元格中,而只是声明为didSelectRowAtIndexPath
:
String *turnId = @"123";
我不会在发件人信息中传递它。
在didSelectRowAtIndexPath
做你的[self performSegueWithIdentifire:@"blah"]
,然后在prepareForSegue
做这样的事情......
- (void)prepareForSegue:... //blah cant remember the name
{
if ([segue.identifier isEqualToString:@"blah"]) {
NewViewController *controller = segue.destinationViewController;
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
//get the object associated with that row and set a variable like...
NSString *selectedString = tableObject.name;
//Then pass the string into the controller...
controller.stringProperty = selectedString;
}
}
然后在NewViewController.h
设置一个@property
接受这个...
@property (nonatomic, strong) NSString *stringProperty;
然后您可以从中访问该值,NewViewCongtroller.m
并将该值传递给它。