在使用tableViews时,我已经多次看到这段代码。
static NSString* CellIdentifier = @"Cell";
UITableViewCell* cell = [tableView dequeue...:CellIdentifier];
if( cell == nil ) /* note the expression used in the conditional */
{
// do stuff
}我也看到了同样的想法,表达如下。
static NSString* CellIdentifier = @"Cell";
UITableViewCell* cell = [tableView dequeue...:CellIdentifier];
if( !cell ) /* note the expression used in the conditional */
{
// do stuff
}据我理解,这些都是一样的。在第一个示例中,如果单元格为==,则nil运算符将返回。第二个条件也只有在单元格为nil时才为真。为什么测试细胞的方法有差异?这些条件还会有不同的东西吗?
发布于 2014-04-11 02:45:38
这些都会给你同样的结果。它更多的是一种风格偏好。
就我个人而言,我觉得if (!cell)只是更容易阅读。
请参阅:http://www.cimgf.com/zds-code-style-guide/
https://stackoverflow.com/questions/23002546
复制相似问题