首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@[indexPath]做什么?

@[indexPath]做什么?
EN

Stack Overflow用户
提问于 2013-09-04 14:09:42
回答 2查看 247关注 0票数 5

我遵循了一个使用UITableView的教程。完成代码

代码语言:javascript
复制
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(editingStyle == UITableViewCellEditingStyleDelete)
    {
        Message *message = [messageList objectAtIndex:indexPath.row];
        [self.persistencyService deleteMessagesFor:message.peer];
        [messageList removeObject:message];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
    }
}

我的问题是:@[indexPath]是做什么的?是不是和?:

代码语言:javascript
复制
[NSArray arrayWithObject:indexPath]
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-09-04 14:10:55

是的,它是相同的,它只是定义数组的简短表示法。您也可以对NSDictionary和NSNumber进行同样的操作。这里有一些样本(这里还有更多)

代码语言:javascript
复制
NSArray *shortNotationArray = @[@"string1", @"string2", @"string3"];

NSDictionary *shortNotationDict = @{@"key1":@"value1", @"key2":@"value2"};

NSNumber *shortNotationNumber = @69;
票数 9
EN

Stack Overflow用户

发布于 2013-09-04 14:16:14

是的,是这样的。这是现代目标的一个新特征-C。

您可以使用文本@创建新的数组,如您的示例中所示。这不仅适用于NSArrays,也适用于NSNumbersNSDictionaries,如下所示:

代码语言:javascript
复制
NSNumber *fortyTwo = @42;   // equivalent to [NSNumber numberWithInt:42]

NSDictionary *dictionary = @{
    @"name" : NSUserName(),
    @"date" : [NSDate date],
    @"processInfo" : [NSProcessInfo processInfo] //dictionary with 3 keys and 3 objects
};

NSArray *array = @[@"a", @"b", @"c"]; //array with 3 objects

访问元素也不错,如下所示:

代码语言:javascript
复制
NSString *test = array[0]; //this gives you the string @"a"

NSDate *date = dictionary[@"date"]; //this access the object with the key @"date" in the dictionary

您可以在这里获得更多信息:http://clang.llvm.org/docs/ObjectiveCLiterals.html

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18616148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档