- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我完成了本教程 Your First iPhone Application效果很好。我的问题是关于教程中的一行,内容如下:
The view controller is also going to be the text field’s delegate; as such, it must adopt the UITextFieldDelegate protocol. To specify that a class adopts a protocol, in the interface add the name of the protocol in angle brackets (<>) after the name of the class from which your class inherits.
如果我从 View Controller 中删除协议(protocol),该方法仍然会被调用(收到消息)并且键盘会被关闭。我注意到 UITextFieldDelegate 的所有方法协议(protocol)是可选的。如果是这样,为什么要声明 View Controller 遵守协议(protocol)呢?我缺少什么? :-)
最佳答案
因为程序员喜欢让事情井井有条。即使协议(protocol)的所有方法都是可选的,如果您的类将用作委托(delegate),那么正式声明您的类实现该协议(protocol)仍然是一种很好的形式。委托(delegate)类可能还要求您的类实现该协议(protocol) - 这意味着如果您实现了这些方法但没有声明您实现了该协议(protocol),您将收到编译警告。
关于iphone - UIVewController 的 UITextFieldDelegate 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1132922/
我有一个带有我制作的方法的应用程序,想法是这个方法将打开我想要的任何 View Controller 。我做到了,所以我必须拥有许多相同代码的副本。但是,它不起作用,Xcode 不断出现错误: Inv
很抱歉重复了同样的问题,但花了很多时间后我无法弄清楚这个问题。 假设,一个 UITableView 有 2 个 table_cell,我想从每个 table_cell 导航不同的 UIViewCont
我完成了本教程 Your First iPhone Application效果很好。我的问题是关于教程中的一行,内容如下: The view controller is also going to b
我希望有人能帮助我解决我遇到的这个问题。 我正在尝试将UIViewController数组添加到UIPageViewController。但是,每当我尝试通过方法 instantiateViewCon
当 ViewController 嵌入到 UINavigationController 中时,我注意到 ViewController 中的 UITablesViews 出现了一些奇怪的行为>。以下是一
我是一名优秀的程序员,十分优秀!