[英]Issue in passing value from one viewcontroller to another viewcontroller
I have one view controller. 我有一个视图控制器。 I added popoverviewcontroller on button action and loaded another viewcontroller which has a uitableview controller.
我在按钮操作上添加了popoverviewcontroller,并加载了另一个具有uitableview控制器的viewcontroller。 When I select a value inside the tableview controller, I am not able to pass the selected value into firstviewcontroller.
当我在tableview控制器中选择一个值时,无法将所选值传递给firstviewcontroller。
The value is coming as null 该值将为空
Second ViewController is having UITableview 第二个ViewController具有UITableview
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[[NSNotificationCenter defaultCenter] postNotificationName:@"RemovePopOverController" object:self];
selectedValue = [titleArray objectAtIndex:indexPath.row];
}
firstviewController firstviewController
-(void)removePopOver:(id)sender{
[self->popoverController dismissPopoverAnimated:YES];
NSString *value = m_titleViewController.selectedValue;
NSLog(@" Value is %@", value);
}
I don't want to use NSUserDefault. 我不想使用NSUserDefault。 Please advice me with a solution for this issue!
请为我提供解决此问题的方法!
Thanks in advance. 提前致谢。
You are posting the notification before setting the value. 您要在设置值之前发布通知。 Try doing it like this:
尝试这样做:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
selectedValue = [titleArray objectAtIndex:indexPath.row];
[[NSNotificationCenter defaultCenter] postNotificationName:@"RemovePopOverController" object:self];
}
Use delegate for your requirement as it best pratcice to use in this situation rather than posting notification. 使用委派来满足您的要求,因为在这种情况下最好使用它,而不要发布通知。
Refer simple-delegate-tutorial-for-ios-development link. 请参阅simple-delegate-tutorial-for-ios-development链接。 Hope helpful.
希望对您有所帮助。
Then you can use Another method like This : 然后,您可以使用其他方法,例如:
Create a String in Appdelegate (ex: stringValue) 在Appdelegate中创建一个字符串(例如:stringValue)
First save your Value into your Appdelegate: 首先将您的价值保存到您的Appdelegate中:
Appdelegate *appdell=[[UIApplication sharedApplication]delegate];
appdell.stringValue=@"Your Value Goes Here";
when ever you want you can get this value. 每当您想要时,您都可以获取此值。
Appdelegate *appdell=[[UIApplication sharedApplication]delegate];
requiredvalue=appdell.stringValue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.