1

当我选择一个新的 viewController 时,a 想传递一个参数,让我们说“turnId”给一个新的ViewController. 我知道我可以在prepareForSegue方法中做到这一点,但是如何将参数传递给prepareForSegue方法本身?我怎样才能从发件人那里得到这个?发件人是didSelectRowAtIndexPath,但该值不在单元格中,而只是声明为didSelectRowAtIndexPath

String *turnId = @"123";
4

1 回答 1

3

我不会在发件人信息中传递它。

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并将该值传递给它。

于 2012-10-22T11:34:16.917 回答