【问题标题】:Basic Objective C Syntax Question基本 Objective C 语法问题
【发布时间】:2011-01-13 19:35:55
【问题描述】:

谁能证实我对这行代码的怀疑。

NSUInteger newPath[] = {[indexPath section],0};

我很确定它是一个 NSUInteger 的 C 数组。 我是对的吗? 你甚至可以制作 Objective C 对象的 C 数组吗?

这是上下文中的代码:

-(UITableViewCellEditingStyle)tableView:(UITableView *) tableViewEditingStyleForRowAtIndexPath:(NSIndexPath*)indexPath{

if ([self isToManyRelationshipSection:[indexPath section]]) {
    NSUInteger newPath[] = {[indexPath section],0};
    NSIndexPath *row0IndexPath = [NSIndexPath indexPathWithIndexes:newPath length:2];

    NSString *rowKey = [rowKeys nestedObjectAtIndexPath:row0IndexPath];
    NSString *rowLabel = [rowLabels nestedObjectAtIndexPath:row0IndexPath];
    NSMutableSet *rowSet = [managedObject mutableSetValueForKey:rowKey];//!!!: to-many?
    NSArray *rowArray = [NSArray arrayByOrderingSet:rowSet byKey:rowLabel ascending:YES];

    if ([indexPath row] >= [rowArray count]) {
        return UITableViewCellEditingStyleInsert;
    }

    return UITableViewCellEditingStyleDelete;
}
return UITableViewCellEditingStyleNone;

【问题讨论】:

  • NSUInteger 不是一个对象,它是一个 c 类型,在这里定义:developer.apple.com/library/ios/documentation/Cocoa/Reference/…
  • 很好,我没有意识到。所以它是一个动态的基本类型。 “在构建 32 位应用程序时,NSUInteger 是 32 位无符号整数。64 位应用程序将 NSUInteger 视为 64 位无符号整数”

标签: objective-c uitableview ios


【解决方案1】:

是的,你是对的。不过……

NSUInteger newPath[] = {[indexPath section],0};
NSIndexPath *row0IndexPath = [NSIndexPath indexPathWithIndexes:newPath length:2];

我会强烈劝阻您不要使用这种格式来创建旨在用于 UITableViewNSIndexPathThere's a convenience method to do this 更简单:

NSIndexPath *row0IndexPath = [NSIndexPath indexPathForRow:0 inSection:[indexPath section]];

【讨论】:

    【解决方案2】:

    我很确定它是一个 NSUInteger 的 C 数组。我说得对吗?

    是的,确实如此。

    你甚至可以制作 Objective C 对象的 C 数组吗?

    你可以。例如,这是一个由两个NSString * 组成的数组:

    NSString *myStrings[] = {@"one", @"two"};
    

    这有用吗?有时,但如果您需要对象数组,使用NSArray 几乎总是有益的。

    【讨论】:

    • @MakingScienceFictionFact 如果它是一个很好的答案,那么我建议你点击答案旁边的检查:)
    【解决方案3】:

    NSUInteger 不是 Objective-c 对象。它是无符号整数的 typedef。根据您的平台,它可能是 int 或 long。但它不是一个对象。所以基本上你只有一个 c 整数数组。

    【讨论】:

      猜你喜欢
      • 2011-02-07
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      • 1970-01-01
      • 2019-03-17
      • 1970-01-01
      相关资源
      最近更新 更多