我遵循了一个使用UITableView的教程。完成代码
- (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]是做什么的?是不是和?:
[NSArray arrayWithObject:indexPath]发布于 2013-09-04 14:10:55
是的,它是相同的,它只是定义数组的简短表示法。您也可以对NSDictionary和NSNumber进行同样的操作。这里有一些样本(这里还有更多)
NSArray *shortNotationArray = @[@"string1", @"string2", @"string3"];
NSDictionary *shortNotationDict = @{@"key1":@"value1", @"key2":@"value2"};
NSNumber *shortNotationNumber = @69;发布于 2013-09-04 14:16:14
是的,是这样的。这是现代目标的一个新特征-C。
您可以使用文本@创建新的数组,如您的示例中所示。这不仅适用于NSArrays,也适用于NSNumbers和NSDictionaries,如下所示:
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访问元素也不错,如下所示:
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
https://stackoverflow.com/questions/18616148
复制相似问题