我们是否总是需要解雇我们提供的ModelViewController?
我已经编辑了整个问题
在以下情况下呈现 ModelView 控制器和关闭模态视图控制器有什么区别?
- HomeView
- TableItemSelection 视图
- PickerView
HomeView 中的 我正在 viewWillAppear
中编写代码,以从 TableView 设置的 NSUserDefault 中获取值。下面是我
- (void)viewDidLoad
{
[super viewDidLoad];
actionMinutes = @"0";
actionSeconds = @"0";
restMinutes = @"0";
restSeconds = @"0";
}
- (void) viewWillAppear:(BOOL)animated
{
actionMin = [actionMinutes intValue];
actionSec = [actionSeconds intValue];
restMin = [restMinutes intValue];
restSec = [restSeconds intValue];
NSLog(@"acMin:%d acSec:%d reMin:%d reSec:%d",actionMin,actionSec,restMin,restSec);
}
在 TableItemSelection View 中的 viewDidLoad (对于初始值)和 viewWillAppear (当来自 tableview 的新值时)的代码 我从 HomeView 展示这个视图。现在我想根据 Table 的 didSelectRowAtIndex 方法在 HomeView 中设置 NSString 的值。我正在使用 NSUserDefault 来设置值。 通过触摸完成按钮,我将呈现 HomeView。 (实际上我必须解雇ModalViewController)但是当我使用解雇时我无法获取HomeView的NSString中的值。我从 PickerView 获取表的值。 (我被指示这样做)。 触摸 DONE 按钮时的表格视图代码
HomeView *homeView = [[HomeView alloc] init];
[homeView.view setBackgroundColor:[UIColor clearColor]];
[homeView.view setFrame:CGRectMake(0 ,40, 320, 460)];
homeView.actionMinutes = [[NSUserDefaults standardUserDefaults] valueForKey:@"actionMinute"];
homeView.actionSeconds = [[NSUserDefaults standardUserDefaults] valueForKey:@"actionSecond"];
homeView.restMinutes = [[NSUserDefaults standardUserDefaults] valueForKey:@"restMinute"];
homeView.restSeconds = [[NSUserDefaults standardUserDefaults] valueForKey:@"restSecond"];
homeView.song = [[NSUserDefaults standardUserDefaults] valueForKey:@"songstring"];
NSLog(@"%@",homeView.actionMinutes);
[self presentModalViewController:homeView animated:YES];
//[self dismissModalViewControllerAnimated:YES]; // if this method is used then no values are passed to HomeView
[homeView release];
下面是我在 PickerView 中 我从 pickerview 获取值,然后将其存储在 UserDefault 中。 下面是我的 pickerview 代码
NSUserDefaults *actionTime = [NSUserDefaults standardUserDefaults];
[actionTime setValue:min forKey:@"actionMinute"];
[actionTime setValue:sec forKey:@"actionSecond"];
那么为什么我在关闭 ModelView 时无法获取 UserDefault 值。???每次呈现一个新视图都会产生一堆视图吗???
I have Edited whole Question
What is the difference between presenting the ModelView Controller and dismissing the modal view controller in following situation??
- HomeView
- TableItemSelection View
- PickerView
In HomeView
I am writing code in viewWillAppear
to fetch values from NSUserDefault that is set from TableView. Below is my code for viewDidLoad (for initial values) and viewWillAppear(when new value from tableview)
- (void)viewDidLoad
{
[super viewDidLoad];
actionMinutes = @"0";
actionSeconds = @"0";
restMinutes = @"0";
restSeconds = @"0";
}
- (void) viewWillAppear:(BOOL)animated
{
actionMin = [actionMinutes intValue];
actionSec = [actionSeconds intValue];
restMin = [restMinutes intValue];
restSec = [restSeconds intValue];
NSLog(@"acMin:%d acSec:%d reMin:%d reSec:%d",actionMin,actionSec,restMin,restSec);
}
In TableItemSelection View
I am presenting this view from HomeView. Now i want to set value of NSString in HomeView based on Table's didSelectRowAtIndex Method. I am using NSUserDefault
to set the value.
And with Done Button touch i am presenting HomeView. (Actually I have to dismissModalViewController) But when i use dismiss I am not able to get values in NSString of HomeView. I am getting values of the table from PickerView. (I am instructed to do that). Below is my code for Table view on DONE button touch
HomeView *homeView = [[HomeView alloc] init];
[homeView.view setBackgroundColor:[UIColor clearColor]];
[homeView.view setFrame:CGRectMake(0 ,40, 320, 460)];
homeView.actionMinutes = [[NSUserDefaults standardUserDefaults] valueForKey:@"actionMinute"];
homeView.actionSeconds = [[NSUserDefaults standardUserDefaults] valueForKey:@"actionSecond"];
homeView.restMinutes = [[NSUserDefaults standardUserDefaults] valueForKey:@"restMinute"];
homeView.restSeconds = [[NSUserDefaults standardUserDefaults] valueForKey:@"restSecond"];
homeView.song = [[NSUserDefaults standardUserDefaults] valueForKey:@"songstring"];
NSLog(@"%@",homeView.actionMinutes);
[self presentModalViewController:homeView animated:YES];
//[self dismissModalViewControllerAnimated:YES]; // if this method is used then no values are passed to HomeView
[homeView release];
In PickerView
I am fetching the values from pickerview and then store it in UserDefault.
below is my code for pickerview
NSUserDefaults *actionTime = [NSUserDefaults standardUserDefaults];
[actionTime setValue:min forKey:@"actionMinute"];
[actionTime setValue:sec forKey:@"actionSecond"];
So why exactly i am not able to get UserDefault values when dismissing ModelView.??? Does presenting a new view everytime will make a stack of views???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@DShah:是的,绝对是..!!
您需要忽略每个模态视图。
另请发布您正在使用的代码。
另请记住,您需要首先放置 NSUserDefaults 行(您使用将 NSString 值分配给 NSUserDefaults 的行),然后将该行放在
dismissModalViewControllerAnimated:
中。如果您需要更多帮助,请给我留言。
希望这对您有帮助。
@DShah: Yes most definitely..!!
You need to dismiss every modal view.
Also Please post the code you are using.
Also keep in mind that you need to put the NSUserDefaults line first (the line which you use assign NSString value to NSUserDefaults) and then put the line where in you
dismissModalViewControllerAnimated:
.If you require more help please leave me a comment.
Hope this helps you.
我认为您正在尝试在
NSUserDefaults
中存储整数值,那么您必须使用 setInteger:forKey: 而不是
setObject:forKey:
。整数不是对象,而是原始类型。要检索它,请使用 integerForKey:。
I think you are trying to store integer value in
NSUserDefaults
then you have toUse setInteger:forKey: instead of
setObject:forKey:
. An integer is not an object, it's a primitive type.To retrieve it use integerForKey:.
这是我能够解决我的问题的最终答案
这是关于“完成”按钮触摸事件的代码...
This is the final answer through which i am able to solve my problem
Here is a code on Done button touch event...