我希望从PopOver View Controller中的父ViewController访问NSString的值。下面是我从tableView中选择行时生成弹出窗口的代码。我需要能够访问editPersonViewController中的varToPass值。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIView *anchorr = tableView;
UIViewController *viewControllerForPopover =
[self.storyboard instantiateViewControllerWithIdentifier:@"editPersonViewController"];
popover = [[UIPopoverController alloc]
initWithContentViewController:viewControllerForPopover];
[popover presentPopoverFromRect:anchorr.frame
inView:anchorr.superview
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Person *person = [arrayOfPersons objectAtIndex:indexPath.row];
// I Need to Send/Access This Value In editPersonViewController
NSString *varToPass = person.personID;
}
答案 0 :(得分:0)
在editPersonViewController.h文件中添加一个名为personID的公共属性,如此
@property (nonatomic, strong) NSString *personID;
然后,只需将editViewController的实例化重新排序为:
UIView *anchorr = tableView;
Person *person = [arrayOfPersons objectAtIndex:indexPath.row];
EditPersonViewController *viewControllerForPopover =
(EditPersonViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"editPersonViewController"];
viewControllerForPopover.personID= person.personID;
popover = [[UIPopoverController alloc]
initWithContentViewController:viewControllerForPopover];
[popover presentPopoverFromRect:anchorr.frame
inView:anchorr.superview
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];