[英]Methods required to be implemented when subclassing in Objective C
I am new at programming in general (though I have had a C class many, many years ago) and am learning Objective-C for programming on the iPhone. 我是编程方面的新手(尽管很多年前我已经有过很多C课程),而且我正在学习Objective-C在iPhone上进行编程。 I have what I think is a simple question, but after looking for a while (days, off and on) I can't find the answer that I'm looking for explicitly.
我认为这是一个简单的问题,但在寻找一段时间(几天,一天又一天)后,我无法找到我正在寻找的答案。
I know that when subclassing an Objective-C class I should implement the initialize method along with the deallocate method (unless using ARC for the latter, if I am correct?). 我知道,当继承Objective-C类时,我应该实现initialize方法和deallocate方法(除非对后者使用ARC,如果我是正确的?)。 The questions are:
问题是:
Thanks for your help! 谢谢你的帮助!
init
and dealloc
if the inherited versions are sufficient. init
和dealloc
。 Also, ARC does not free you from having to write dealloc
in all cases (but it certainly covers the overwhelming majority). dealloc
(但它绝对覆盖了绝大多数)。 For example, if you allocate memory for your object using malloc
, you need to free it in the dealloc
. malloc
为对象分配内存,则需要在dealloc
释放它。 @requried
. @requried
方法的协议时。 These methods are marked in the protocol reference. tableView:cellForRowAtIndexPath:
and tableView:numberOfRowsInSection:
are marked with the "required method" tag in Apple's documentation . tableView:cellForRowAtIndexPath:
和tableView:numberOfRowsInSection:
在Apple的文档中标有“required method”标记。 No methods are required when subclassing an NSObject (or any of their subclasses, such as UIViewController, UIView, etc. etc.). 子类化NSObject(或其任何子类,如UIViewController,UIView等)时,不需要任何方法。
If you create a new, let's say UIViewController, it's generally a good idea to keep the methods you find in the newly created file as a guideline/template, but you're not really required to keep any of the methods. 如果您创建一个新的,比如说UIViewController,通常最好将您在新创建的文件中找到的方法作为指南/模板,但实际上并不需要保留任何方法。 The super class will always call the methods on itself.
超类总是会调用方法本身。
Be aware, though, some methods you have to call super, like viewWillAppear, etc. 但请注意,您必须调用一些超级方法,例如viewWillAppear等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.