我们是否总是需要解雇我们提供的ModelViewController?

发布于 2024-12-02 09:33:58 字数 2348 浏览 0 评论 0原文

我已经编辑了整个问题

在以下情况下呈现 ModelView 控制器和关闭模态视图控制器有什么区别?

  1. HomeView
  2. TableItemSelection 视图
  3. 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??

  1. HomeView
  2. TableItemSelection View
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝戈者 2024-12-09 09:33:59

@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.

萌辣 2024-12-09 09:33:59

我认为您正在尝试在 NSUserDefaults 中存储整数值,那么您必须

使用 setInteger:forKey: 而不是 setObject:forKey:。整数不是对象,而是原始类型。

要检索它,请使用 integerForKey:

I think you are trying to store integer value in NSUserDefaults then you have to

Use setInteger:forKey: instead of setObject:forKey:. An integer is not an object, it's a primitive type.

To retrieve it use integerForKey:.

撧情箌佬 2024-12-09 09:33:59

这是我能够解决我的问题的最终答案

这是关于“完成”按钮触摸事件的代码...

- (IBAction) btnDonePressed:(id)sender {
    aurioTouchAppDelegate *appDelegate = (aurioTouchAppDelegate *) [[UIApplication sharedApplication] delegate];

    appDelegate.homeView.actionMinutes = [[NSUserDefaults standardUserDefaults] valueForKey:@"actionMinute"];
    appDelegate.homeView.actionSeconds = [[NSUserDefaults standardUserDefaults] valueForKey:@"actionSecond"];
    appDelegate.homeView.restMinutes = [[NSUserDefaults standardUserDefaults] valueForKey:@"restMinute"];
    appDelegate.homeView.restSeconds = [[NSUserDefaults standardUserDefaults] valueForKey:@"restSecond"];     
//    [self presentModalViewController:homeView animated:YES];
    [self dismissModalViewControllerAnimated:YES];    // if this method is used then no values are passed to HomeView
}

This is the final answer through which i am able to solve my problem

Here is a code on Done button touch event...

- (IBAction) btnDonePressed:(id)sender {
    aurioTouchAppDelegate *appDelegate = (aurioTouchAppDelegate *) [[UIApplication sharedApplication] delegate];

    appDelegate.homeView.actionMinutes = [[NSUserDefaults standardUserDefaults] valueForKey:@"actionMinute"];
    appDelegate.homeView.actionSeconds = [[NSUserDefaults standardUserDefaults] valueForKey:@"actionSecond"];
    appDelegate.homeView.restMinutes = [[NSUserDefaults standardUserDefaults] valueForKey:@"restMinute"];
    appDelegate.homeView.restSeconds = [[NSUserDefaults standardUserDefaults] valueForKey:@"restSecond"];     
//    [self presentModalViewController:homeView animated:YES];
    [self dismissModalViewControllerAnimated:YES];    // if this method is used then no values are passed to HomeView
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文