如何显示从uipickerview到另一个视图的选定值
答
当用户关闭第二个视图时,通常会将值数据存储在模型中。当第一个视图重新出现(或使用通知)时,它会从模型中读取值。您的模型数据可能是plist或nsuserdefaults或核心数据等。
或者,您可以在创建第二个viewController并将其作为第二个viewController上的属性进行分配时创建对第一个viewController的引用。然后,在作用在第二的viewController有一个“路径”到第一个的viewController:
第一的viewController将具有属性,例如:
NSString *myStr; // in the header
@property (nonatomic, retain) NSString *myStr; // in the header file
@synthesize myStr; // in the implementation file
第二的viewController将具有属性,例如:
firstViewController *firstVC; // in the header
@property (nonatomic, retain) firstViewController *firstVC; // in the header file
@synthesize firstVC; // in the implementation file
当您创建第二个的viewController,你会做这样的事情:
secondViewController.firstVC = self; // in the implementation file
然后,当你想更新第一的ViewController myStr中(从第二的viewController),你会做这样的事情:
firstVC = @" my new value "; // in the implementation file
检查这个线程 - http://stackoverflow.com/questions/5725580/how-to -get-selected-value-from-uipickerview – rishi 2012-01-18 07:05:33
您是否试图在另一个视图中使用,比如您要查看还是在之前查看 – 2012-01-18 07:05:41
是的,例如,当我点击它时,第一个视图中有按钮。它将在第二视图上移动,并从拾取器中选择一些值。然后它将返回到第一视图并在按钮上显示所选值。 – user1011291 2012-01-18 10:48:03