为什么是textFieldDidEndEditing:没有被调用? [英] why is textFieldDidEndEditing: not being called?

查看:1977
本文介绍了为什么是textFieldDidEndEditing:没有被调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩我的第一个iphone应用程序; SDK 3.0。我有一个UITextField,当文本被输入到那里,我想从文本字段获取doubleValue并执行一些计算,并在UITableView中显示它们。

I'm playing with writing my first iphone app; SDK 3.0. I've got a UITextField, and when text gets entered into that, I want to obtain the doubleValue from the text field and perform some computations and display them in a UITableView.

UITextField的委托采用UITextFieldDelegate协议,并且实现textFieldShouldReturn:和textFieldDidEndEditing:方法。 textFieldShouldReturn:resigns第一个响应者状态,根据docs也应该触发textFieldDidEndEditing :,但我从来没有看到textFieldDidEndEditing:调用。

The delegate for the UITextField adopts the UITextFieldDelegate protocol, and implements both textFieldShouldReturn: and textFieldDidEndEditing: methods. textFieldShouldReturn: resigns first responder status which, according to docs should also trigger textFieldDidEndEditing:, but I never see textFieldDidEndEditing: called.

- (BOOL)textFieldShouldReturn:(UITextField*)theTextField {
    if (theTextField == thresholdValue) {
        [thresholdValue resignFirstResponder];
    }
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    [self updateThresholdValue:textField];
}

可能值得注意的是,我也尝试连接一些textfield事件

It may be worth noting that I also tried connecting some of the textfield events to the delegate and having the event call updateThresholdValue: directly, but that didn't work either.

推荐答案

正如在其中一个提到的那样,评论,我尝试复制一个更简单的版本的我试图做一个HelloWorld应用程序,它的工作在第一次尝试,没有问题,正如预期。面对这一点,我开始怀疑了一点。

As mentioned in one of the comments, I tried replicating a simpler version of what I was trying to do using a HelloWorld app, and it worked on the first try, with no problems, just as expected. Faced with that, I began to wonder a bit.

在所有的google搜索我试图找到一个答案这个问题,我碰到一个链接,人有一个问题,事件不发射从按钮,结果是,问题是与按钮被放置的视图,该视图有另一个子视图作为对等按钮,该子视图以某种方式吃事件而不是让他们去他们被指示的地方。这种情况与我的情况不完全相同,但是听起来很接近,调查是值得的。尽管在这里收到了很多好的建议,但是没有一个成功的结果。

Somewhere in all the googling I did to try to get an answer to this problem, I ran across a link where a person was having a problem with events not firing from a button, and it turned out that the problem was related to the view in which the button was placed and that view having another subview as a peer to the button, and that subview was somehow eating the events rather than allowing them to go where they'd been directed. The scenario wasn't exactly the same as mine, but it sounded close enough that investigation would be worthwhile. Despite all the excellent advice received here, none had yet borne fruit.

昨晚,我决定从头开始重新创建nib文件有第一个),我得到它的工作。关键的区别似乎是,我在原来的非工作的nib文件,我拖动了一个 TableViewController 从调色板,然后将其类型更改为我的子类 PZTableViewController 。当我在新的笔尖做同样的事情,事件没有发射。如果,另一方面,我删除了拖动的 TableViewController ,而是只是拖动一个 NSObject 并更改了类到 PZTableViewController 并且一切顺利,所有的只是工作。

Last night I decided to completely re-create the nib file from scratch (made a copy of what I had first), and I got it to work. The key difference seems to be that I in the original non-working nib file, I had dragged over a TableViewController from the palette, then changed its type to my subclass PZTableViewController. When I did that same thing in my new nib, the events didn't fire. If, on the other hand, I removed the dragged-over TableViewController and instead just dragged over an NSObject and changed its class to PZTableViewController and plumbed everything up, it all "just worked".

我将尝试追逐链接,让我开始这种思维方式,并发布为一个编辑或作为一个评论。

I will try to chase down the link that got me started on this line of thinking and post it either as an edit or as a comment.

这也不是一个完整的答案,因为我还不明白来自于调色板 TableViewController 和我的子类之间的差异。当我想出来,我会通过编辑或评论更新这个答案。

This is also not a complete answer because I do not yet understand the difference between the from-the-palette TableViewController and my subclass. When I figure that out, I will update this answer via edit or comment.

这篇关于为什么是textFieldDidEndEditing:没有被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆