iOS5 中 UIPickerView selectedRowInComponent 的不同奇怪行为

发布于 2024-12-11 12:32:10 字数 1360 浏览 1 评论 0原文

iOS5 更新后,我的应用程序发生了奇怪的事情。

我有一个 UIPickerView 并使用 [customPickerView selectedRowInComponent:0] 来获取选取的组件。用户选择第二行(索引为 1),

因此看起来像:

i = [customPickerView selectedRowInComponent:0];   // -> i is 1 here, is OK!
[smsAgent  sendSMS:smsTxt]; //just call another method to send a SMS

检查时 i 的值正常。 现在我只是调用普通的短信对话 smsAgent ,它看起来基本上是这样的:

smsAgent...
      MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
      picker.messageComposeDelegate = delegate;
      picker.recipients =[NSArray arrayWithObject: myTelNumber];  
      [delegate presentModalViewController:picker animated:YES];

当然不会对我的选择器做任何事情。

但是当这个“返回”时,

    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
        [self dismissModalViewControllerAnimated:NO]; //take away the SMS screen fast, so we can send selectModeVCDidFinish to take away ourselves
        int j = [customPickerView selectedRowInComponent:0];
        [self.delegate selectModeVCDidFinish: selectedMode];
}

j又是0,而不是1

当然,customPickerView 没有发生任何事情 - 我真的很困惑 - 这里发生了什么?

在更新到iOS5之前没有任何问题。

有什么我错过的吗?

非常感谢

I have a strange thing happening with my app now after iOS5 updates.

I have a UIPickerView and use [customPickerView selectedRowInComponent:0] to get the picked component. The user picks the second row (with index 1)

So it looks like:

i = [customPickerView selectedRowInComponent:0];   // -> i is 1 here, is OK!
[smsAgent  sendSMS:smsTxt]; //just call another method to send a SMS

The value of i is OK when checking.
Now I just call a the normal SMS dialogue smsAgent which looks essentially like this:

smsAgent...
      MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
      picker.messageComposeDelegate = delegate;
      picker.recipients =[NSArray arrayWithObject: myTelNumber];  
      [delegate presentModalViewController:picker animated:YES];

certainly not doing anything to my picker.

But when this "returns" in

    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
        [self dismissModalViewControllerAnimated:NO]; //take away the SMS screen fast, so we can send selectModeVCDidFinish to take away ourselves
        int j = [customPickerView selectedRowInComponent:0];
        [self.delegate selectModeVCDidFinish: selectedMode];
}

the value j is 0 again, not 1!

For sure nothing happens to the customPickerView - I am really puzzled - what's going on here?

Before updating to iOS5 there was no problem whatsoever.

Is there something that I missed?

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

香橙ぽ 2024-12-18 12:32:10

感谢您详细解释问题。我的 UIPickerViews 有问题。正如我在上面的评论中提到的,我的代码基于 CustomPickerView - http://iphonedevelopment.blogspot.co.uk/2009/02/longer-spinning-blurring-v20.html

此代码与版本不同5.0。经过大量研究后,我发现这不是 UIPicker 调用委托函数的顺序/顺序的问题。

但非官方函数“scrollAnimationDuration”已被弃用且无法使用。这就是 UIPicker 无法滚动较长时间的原因(就像 iOS 4.3.3 及更低版本一样)。

Thanks for explaining the problem in detail. I had a problem with my UIPickerViews. As mentioned in my comment above, my code was based on CustomPickerView - http://iphonedevelopment.blogspot.co.uk/2009/02/longer-spinning-blurring-v20.html

This code fell apart from version 5.0. After doing a lot of research I found that it was not the problem with the sequence/order of delegate functions being called for UIPicker.

But the unofficial function "scrollAnimationDuration" in particular has been deprecated and not available for use. This was the reason for UIPicker not scrolling for longer duration (as it did for iOS 4.3.3 and below).

寒江雪… 2024-12-18 12:32:10

正如我在评论中所写的,这种行为的原因是调用方法的顺序。我来详细解释一下:

启动屏幕screenVC有普通方法viewWillAppear和viewDidAppear。在这些消息中,选择器被创建(或任何元素)并被设置为底层数据结构提供的值。所以假设选择器得到 10。

现在,当选择放入变量中的不同值 20 时,我认为这将是 SAVE。

现在,短信对话框打开,并且发送短信。

但现在发生的事情就是造成这个奇怪问题的原因。当 SMS 对话框消失时,screenVC 会触发 viewWillAppear,这会将变量 BACK 设置为 10(因为数据结构尚未更新)。

现在 SMS 返回到 didFinishWithResult 并且底层的 20 丢失了。

因此,您需要做的就是确保用于从 sms didFinishWithResult 中更新数据结构的变量作为参数传递到屏幕的关闭调用中。

只是一个附加问题。更令人惊讶的是,如果 screenVC 打开另一个只有选择器(并将值设置为 10)的 screen2VC,然后这个 screen2VC 打开短信对话框。当短信对话框返回时,它会导致 screen2VC 调用 viewWillAppear 和 viewDidAppear,即使它们已被关闭。

我想发生这种情况是因为当短信对话框关闭时短信对话框启动屏幕需要在那里。

希望我能解释得足够好以便理解——如果不清楚就问。

作为最后的评论:将调试语句放入正在分配相关变量的代码中 - 在那里您可以看到 allocateemnt 正在被调用,即使您没有预料到/想到它。

As I have written in my comment, the reason for this behaviour is the order in which the methods get called. Let me explain in detail:

The starting screen screenVC has the normal methods viewWillAppear and viewDidAppear. Within these messages the picker gets created (or whatever element) and is set to the value that is provided by the underlying data structures. SO lets say the picker gets 10.

Now when choosing a different value 20 that's put in a variable and I thought this would be SAVE.

Now the SMS dialog opens and one sends the sms.

But what happens now is the reason for this strange problem. When the SMS dialog disappears the screenVC fires viewWillAppear, this sets the variable BACK to 10 (since the data structures have not been updated yet)

Now the sms comes back into didFinishWithResult and the underlying 20 is lost.

So all you need to do is to ensure that the variable used to update your data structure from within sms didFinishWithResult is passed as a parameter with your dismiss call of the screen.

Just an additional issue. Even more surprising if screenVC opens another screen2VC which only has the picker (and sets the value to 10) and this one then opens the sms dialog. When the sms dialog returns it causes screen2VC to call viewWillAppear and viewDidAppear even though they were dismissed.

I suppose this happens because the sms dialog starter screen needs to be there when the sms dialog dismisses.

Hopefully I could explain well enough to understand - just ask if its not clear.

And as a last comment: put debug statements into the code where your variable in question is beeing assigned - there you can see that the assignemnt is being called even though you did not expect/think of it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文