获取不同视图中存在的选取器视图的选定值,并在其他视图中使用该字符串
我在视图控制器页面中有一个选择器视图,例如视图控制器1。现在我需要从另一个视图控制器(例如视图控制器2)中的选择器视图访问选定的字符串值。
这是因为,我有一个显示的表视图保存的数据对应于4个组,即我的应用程序是提醒应用程序,用户保存提醒,在查看提醒页面中可见。提醒由用户保存在各自的组中,比如朋友、家人、办公室等......所以我之前曾在错误的编程中检索过上下文,即
我使用了 4 个视图控制器来显示与 4 个组相对应的提醒,即用 FriendsViewController 来显示与使用查询的朋友相对应的提醒,
NSString *getQuery = [NSString stringWithFormat:@"SELECT * FROM reminders WHERE Grp = 'Friends' GROUP BY Name,Event,Date"];
就像家庭、办公室和熟人组一样。因此,将不良编程的上下文转变为良好的编程习惯,我有一个使用查询的想法:
NSString *getQuery = [NSString stringWithFormat:@"SELECT * FROM reminders WHERE Grp = '%@' GROUP BY Name,Event,Date",**selected string value from the picker in previous view**];
请确定我想要做的更改,即 Grp = '%@' - 该字符串是从上一个视图中的选择器视图中的行组件中选择的值。
我知道有两种可能的访问方式,
1.subclassing the view controller i.e.
@interface viewController2:viewController1,but I already have subclassed i.e.:
@interface viewController2:addReminderController ,so I cant subclass twice,I am not aware too!
2. Creating an instance object of the viewController1 i.e.
viewController1 *vC1,我尝试像 [vC1.groupPicker selectedRowInComponent:row] 一样访问 groupPicker,
但正如我们所料,它会抛出一个错误,即 row undeclared ,
我尝试访问数组,因为我已将 groupPicker 组件中的行数分配为 [self.groupArray count],所以我尝试使该策略在viewController2 也是如此:
[vC1.groupArray objectAtIndex:row],as expected the same error: **row undeclared**
那么我怎样才能访问在前一个视图中存在的选择器视图中选择的行(字符串),以便我可以表现出良好的编程习惯,这对于像我这样的新手来说是一个好兆头:)
请帮助给我一些宝贵的建议
提前感谢大家:)
I have a picker view in a view controller page,say view controller1.Now I have a requirement of accessing the selected string value from that picker view in another view controller say view controller 2.
This is because,I have a table view which displays the saved data corresponding to 4 groups i.e. my application is reminder application which user saves the reminder,that is visible in view reminder page.The reminders are saved by the user in respective groups,say friends,family,office etc... So I have earlier retrieved in a bad programming context,i.e.
I took 4 view controllers for displaying reminders corresponding to 4 groups i.e. say friendsViewController for displaying reminders corresponding to friends using the query
NSString *getQuery = [NSString stringWithFormat:@"SELECT * FROM reminders WHERE Grp = 'Friends' GROUP BY Name,Event,Date"];
Like wise for group family,office and acquaintances.Hence for shifting the context of bad programming to a good programming habit,I have got an idea of using the query:
NSString *getQuery = [NSString stringWithFormat:@"SELECT * FROM reminders WHERE Grp = '%@' GROUP BY Name,Event,Date",**selected string value from the picker in previous view**];
Please identify the change I am trying to do,i.e. Grp = '%@'-The string is selected value from row component in picker view which is in previous view.
I am aware of 2 possible ways for getting access,
1.subclassing the view controller i.e.
@interface viewController2:viewController1,but I already have subclassed i.e.:
@interface viewController2:addReminderController ,so I cant subclass twice,I am not aware too!
2. Creating an instance object of the viewController1 i.e.
viewController1 *vC1 and I tried to access the groupPicker like [vC1.groupPicker selectedRowInComponent:row],
but as we can expect it throws an error i.e. row undeclared ,
I tried to access the array as I have assigned for number of rows in component for groupPicker as [self.groupArray count],so I tried to make the tactic work in viewController2 too i.e.:
[vC1.groupArray objectAtIndex:row],as expected the same error: **row undeclared**
So how can I get access to row(string) selected in picker view which is present in previous view,so that I can exhibit good programming habit which is a good sign in future for a fresher like me :)
Please help me with some valuable suggestions
Thanks all in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第 1 步:在 appDelegate 中获取一个 NSString 变量。
步骤 2:在您想要设置值和获取值的两个视图中创建 appDelegate 实例,如下所示。
步骤 3:在实现文件中初始化 appDelgate,如下所示,
在此语句之后,您可以使用在应用程序的 appDelegate 中声明的两个视图控制器中的字符串变量。
就是这样。现在您可以从第一个视图分配值并在第二个视图中访问它。
Step 1: Take a NSString variable in your appDelegate.
Step 2: create instance of appDelegate in your both view were your want to set value and get value as following.
Step 3: init appDelgate in implementation file as following
after this statement you can use the string variable from both view controller you declared in appDelegate of you application.
That's it. now you can assign value from first view and access it in second view.
您可以在 Secondview 中全局声明 NSString ,最好采取一个按钮,并且在该操作中您必须
在第一个视图中全局编写 Take a NSString *selectedString
在 Pickerview 委托方法
stringFromPrevView 中,此字符串将根据您的要求在您的 SecondView 中使用
我希望这会对您有所帮助
You can declare NSString in Secondview globally and it is better to take a button and in that action You have to write
Take a NSString *selectedString globally in firest view
in Pickerview delegate method
stringFromPrevView this string will be use in Your SecondView as per Your requirement
I hope this will helps You