提问人:KiloOne 提问时间:5/11/2022 最后编辑:KiloOne 更新时间:5/11/2022 访问量:40
访问 NSMutableArray 中的对象的语法
Syntax to access objects in my NSMutableArray
问:
我在 NSMutableArray 中有 2 个对象,一个是 CBPeripheral 对象,另一个是 NSString。
在这里,您可以看到 NSMutableArray 包含两个对象:
然后,在第 1249 行中,我尝试将“periph”对象分配给 CBPeripheral,在第 1252 行中,我尝试将“ADVTname”分配给文本标签。
第 1249 行和第 1252 行都不是我尝试执行的操作的正确语法(第 1252 行甚至无法编译)。
有人可以告诉我如何访问我的“thisrow”NSMutableArray 中的对象吗?
谢谢 山谷
编辑#1:我试图理解“thisrow”如何成为NSDictionay,但我被难住了,这里是将对象放入“thisrow”的所有代码片段。也许我的整个想法存在一个缺陷,即试图记住添加到_foundbleHalos的所有外围设备的 ADVTname。
//AFTER @interface foundblehalos was defined
@property (strong,nonatomic) NSMutableArray* foundbleHalos;
//in (void)centralManager > didDiscoverPeripheral
[_foundbleHalos addObject:@{@"periph": peripheral, @"ADVTname": ADVRTperipheralName}]; //2022-b70-3
//when I try to populate a TableView with all the ADVTnames we found:
NSMutableArray *thisrow = [_foundbleHalos objectAtIndex:indexPath.row];
blecell.textLabel.text = [NSString stringWithFormat:@"%@",thisrow.lastObject];
CBPeripheral* HaloForRow = (CBPeripheral*) thisrow[0];
编辑#2:好吧,我认为以下代码是我的主题问题的答案,但我不明白它,因为我不知道为什么当我最初将其定义为NSMutableArray时,“thisrow”变成了字典类型:
//AFTER @interface foundblehalos was defined
@property (strong,nonatomic) NSMutableArray* foundbleHalos;
//in (void)centralManager > didDiscoverPeripheral
[_foundbleHalos addObject:@{@"periph": peripheral, @"ADVTname": ADVRTperipheralName}]; //2022-b70-3
//when I try to populate a TableView with all the ADVTnames we found:
NSDictionary *thisrow = [_foundbleHalos objectAtIndex:indexPath.row];
blecell.textLabel.text = thisrow[@"ADVTname"];
CBPeripheral* HaloForRow = (CBPeripheral*) thisrow[@"periph"];
答: 暂无答案
评论
thisrow
不是数组。这是一本字典NSMutableArray
[_foundbleHalos addObject:aDictionary]