从init方法调用方法? [英] Calling a method from the init method?
本文介绍了从init方法调用方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有两个这样定义的属性:
Say I have two properties defined as such:
@property (nonatomic, strong) UITableView *parentTableView;
@property (nonatomic, strong) NSMutableArray *headersArray;
和方法:
-(void)prepareTags;
并说我有一个像这样的初始化方法:
and say I have an init method like this:
-(id)initWithParentTableView:(UITableView*)parentTable
{
if(self = [super init])
{
//1
NSMutableArray *array = [[NSMutableArray alloc] init];
headersArray = array;
//2
self.parentTableView = parentTable;
//3
[self prepareTags];
}
return self;
}
- 这是在init方法中设置标头数组的正确方法吗?
- 我可以通过init方法调用
self.parentTableView
吗? - 我允许从init方法中调用方法(在这种情况下,prepareTags方法也调用
self
.即使初始化方法还没有返回?
- Is this the correct way to set up the headers array in an init method?
- Am I allowed to call
self.parentTableView
from the init method? - Am I allowed to call a method from the init method (in this case, the prepareTags method calls
self
too. Willself
be ready to use, even though the init method hasn't returned yet?
推荐答案
分别(我将使用列表格式,但不能使其与blockquotes一起使用!!):
Respectively (I'd use list formatting but I can't make it work with blockquotes...!):
是的,但是没有必要使用 array
变量,您也可以这样做: headersArray = [[NSMutableArray alloc] init];
Yes, but there's no point having the array
variable, you might as well just do: headersArray = [[NSMutableArray alloc] init];
查看全文