通过 Xcode 进行 iOS 开发:UIView & UITextView/UIPickerView - 无法分配委托?
直到昨晚更新 Xcode 为止,这一切都运行良好(尽管可能纯粹是运气不好!)。
现在,在分配委托时,我的 UITextViews、Fields 和 UIPickerViews 出现错误:
[m_textField setDelegate:GAMESTATE->glView.self];
m_textField 被定义为 UITextField*。 glView 被定义为 UIView*。为了简单起见,我只为整个应用程序使用一个 UIView(也可能是一个问题)。我只需要访问应用程序中的几个基本操作即可从用户那里获取简单的文本信息。现在我得到了错误:
Cannot initialize a parameter of type 'id<UITextFieldDelegate>' with an rvalue of type 'UIView*'
就像我说的,我可能一开始就做错了什么,而且这完全是靠运气!如果有帮助,我已经将我的 UIView 子类化为加速计委托,如下所示:
@interface GLView : UIView <UIAccelerometerDelegate>
任何帮助、建议或提示将不胜感激。今天早上我偶然读了一些书,并复习了几本苹果文档,但似乎不可能快速解决问题。我并不反对重构从用户那里获取输入的方式,我可以用手到达那里。
Up until updating Xcode last night, this was working great (though probably through sheer dumb luck!).
I'm getting an error now for my UITextViews, Fields and UIPickerViews when assigning the delegate:
[m_textField setDelegate:GAMESTATE->glView.self];
m_textField is defined as UITextField*. glView is defined as a UIView*. To keep things simple, I'm using just one UIView for the entire app (could also be a problem). I only need access to a couple of basic operations in the app to get simple text info from the user. Now I get the error:
Cannot initialize a parameter of type 'id<UITextFieldDelegate>' with an rvalue of type 'UIView*'
Like I said, I probably was doing something wrong in the first place, and it only worked through sheer, dumb luck! If it helps, I'm already subclassing my UIView as an Accelerometer Delegate, as such:
@interface GLView : UIView <UIAccelerometerDelegate>
Any help, suggestions or tips would be greatly appreciated. I've stumbled through some books this morning and brushed up on several Apple docs, but a quick work-around doesn't seem possible. I'm not adverse to refactoring the way I take input from the user, I could just use a hand getting there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
例如,您应该创建将委托
UITextView
的NSObject
:UITextViewDelegate
。UIPickerView
:UIPickerViewDelegate
您的类声明应如下所示:
然后您应该分配+初始化它并将其设置为文本/选择器视图的委托人:
不要忘记在
MyViewDelegator
中实现对于协议来说不是可选的适当方法。You should create, for example,
NSObject
that will delegateUITextView
:UITextViewDelegate
.UIPickerView
:UIPickerViewDelegate
Your class declaration should look like this:
Then you should alloc+init it and set it as delegator of your text/picker views:
Don't forget to implement appropriate methods in
MyViewDelegator
that are not optional for protocols.