我正在研究UIPopover并且在一个例子中我发现Popover创建了对象但是然后将对象分配给了该属性Viewcontroller.
UIPopoverController* aPopover = [[UIPopoverController alloc] initWithContentViewController:content];
self.popoverController = aPopover;
Run Code Online (Sandbox Code Playgroud)
这种转让的优点是什么,以及不直接将财产分配给财产的任何理由?
它没有"优点".话
self.popoverController =
[[UIPopoverController alloc] initWithContentViewController:content];
Run Code Online (Sandbox Code Playgroud)
绝对等同.
另一方面,使用临时变量(aPopover)没有任何问题,如示例所示.它只是一个名字(一个指针); 没有明显的空间或时间浪费.此外,要避免self.popoverController 重复说(设置或获取其值),因为这是一个方法调用 - 您正在通过setter方法或getter方法(可能是合成的,可能有副作用,并且在事实上需要一些额外的时间).因此,当有很多配置需要完成时(例如),最好按照示例中的说明进行:
UIPopoverController* aPopover =
[[UIPopoverController alloc] initWithContentViewController:content];
// lots of configuration here, using the local automatic variable aPopover...
// ...and then, only when it is all done, call the setter:
self.popoverController = aPopover;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
89 次 |
| 最近记录: |