黑马程序员技术交流社区
标题: loadNibNamed方法 [打印本页]
作者: 余丽丽 时间: 2015-8-7 22:59
标题: loadNibNamed方法
loadNibNamed方法:
-([url=]NSArray[/url]*)loadNibNamed:([url=]NSString[/url]*)nameowner:(id)owneroptions:([url=]NSDictionary[/url]*)options
参数:
name:nib文件的名称
owner:指定name参数所指代的nib文件的File's Owner
options:当nib文件开始时,需要的数据
返回值:返回符合对象的数组。
例子:初始化一个View
CustomCell*cell=(CustomCell*)[tableViewdequeueReusableCellWithIdentifier:CustomCellTableIdentifier];
if(cell==nil) {
NSArray*nib=[[NSBundlemainBundle]loadNibNamed:@"CustomCell"owner:self options:nil];
cell=[nibobjectAtIndex:0];//因为返回的是数组
}
在这个时候生成后会让引用计数器变为1,但是需要注意得,owner:self ,在owner自己dealloc得时候,系统会自动帮你将你自定义view引用计数器-1得。
特别注意:
loadNibNamed:owner:options: 这个函数会返回一个nib的数组。不过,在iPhone2.1包括以后的版本,这个数组的第一个元素,即nib[0]表示的就是除了File‘s Owner 和 File Responder后的第一个东西。在iPhon2.1之前的版本,nib[0]是File's Owner,nib[1]才是除了File‘s Owner 和 File Responder后的第一个东西。
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) |
黑马程序员IT技术论坛 X3.2 |