Ios 获取_detailItem并在显示前更改标签数据
我用头撞桌子已经一个小时了。我需要将一个细节项从一个视图控制器传递到下一个视图控制器,然后在显示它之前更新视图。就我而言,我无法让它正常工作。以下是我正在使用的代码: VC#1(从以下位置传递数据): VC#2(数据发送至): VC#2顶部的NSLog报告了正确的字符串,但是如果我尝试使用或比较该字符串,它似乎不起作用。Ios 获取_detailItem并在显示前更改标签数据,ios,Ios,我用头撞桌子已经一个小时了。我需要将一个细节项从一个视图控制器传递到下一个视图控制器,然后在显示它之前更新视图。就我而言,我无法让它正常工作。以下是我正在使用的代码: VC#1(从以下位置传递数据): VC#2(数据发送至): VC#2顶部的NSLog报告了正确的字符串,但是如果我尝试使用或比较该字符串,它似乎不起作用。 InputViewController *input = [[InputViewController alloc]init]; self.tdModal = input; 分
InputViewController *input = [[InputViewController alloc]init];
self.tdModal = input;
分配新的InputViewController
并将其存储在属性中
但是这个
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
InputViewController *viewController = (InputViewController *)[storyboard instantiateViewControllerWithIdentifier:@"VDI"];
[self presentViewController:viewController animated:YES completion:nil];
分配另一个InputViewController
并显示它
这个
在原始视图控制器中设置detailItem
属性-您尚未显示的属性
你想要的是
-(IBAction)NotOwed:(id)sender{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
self.tdModal = (InputViewController *)[storyboard instantiateViewControllerWithIdentifier:@"VDI"];
[[self presentViewController:self.tdModal animated:YES completion:nil];
[self.tdModal setDetailItem:@"NotOwed"];
// do any setup you need for myNewVC
[self dismissSemiModalViewController:self];
}
或者,由于您将退出当前VC,您可以继续使用本地InputViewController
变量-您需要保持一致,并使用本地变量或属性
此外,如果
InputViewController
与当前视图控制器来自同一情节提要,则可以将它们与segue链接并触发segue。然后,您可以在prepareForSegue
中设置DetailItem,向您致敬!谢谢没关系。有时你就是看不见它,一双新鲜的眼睛会立刻发现它
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
InputViewController *viewController = (InputViewController *)[storyboard instantiateViewControllerWithIdentifier:@"VDI"];
[self presentViewController:viewController animated:YES completion:nil];
[self.tdModal setDetailItem:@"NotOwed"];
-(IBAction)NotOwed:(id)sender{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
self.tdModal = (InputViewController *)[storyboard instantiateViewControllerWithIdentifier:@"VDI"];
[[self presentViewController:self.tdModal animated:YES completion:nil];
[self.tdModal setDetailItem:@"NotOwed"];
// do any setup you need for myNewVC
[self dismissSemiModalViewController:self];
}