Objective c 如何获取在NSMutableDictionary中设置的对象并制作触摸界面?

Objective c 如何获取在NSMutableDictionary中设置的对象并制作触摸界面?,objective-c,nsdictionary,Objective C,Nsdictionary,我正在尝试使用NSMutableDictionary制作具有触摸功能的网格。我在视图控制器的viewDidLoad函数中使用以下命令创建了一个坐标网格(\u CoordinatedRecords是我的字典): [self _loopOnCellWithIterator: (^(int iLooper, int jLooper) { int cellWidth = 10; int space = 1; [_coordinateRecords setObject: [NSI

我正在尝试使用
NSMutableDictionary
制作具有触摸功能的网格。我在视图控制器的viewDidLoad函数中使用以下命令创建了一个坐标网格(
\u CoordinatedRecords
是我的字典):

[self _loopOnCellWithIterator: (^(int iLooper, int jLooper)
{
    int cellWidth = 10;
    int space = 1;

    [_coordinateRecords setObject: [NSIndexPath indexPathForRow: iLooper inSection: jLooper] forKey: [NSValue valueWithPointer: redCell]];

    redCell = [[[UIView alloc] initWithFrame: CGRectMake(iLooper * (cellWidth + space) + 24.25,
                                                         jLooper * (cellWidth + space) + 110,
                                                         cellWidth, cellWidth)] init];
    _cells[iLooper][jLooper] = redCell;

    [redCell setBackgroundColor: [UIColor blueColor]];

    [[self view] addSubview: redCell];
})];
使用此块:

- (void)_loopOnCellWithIterator: (void(^)(int iLooper, int jLooper))iterator
{
    for (int iLooper = 0; iLooper < kCellSize; iLooper++)
    {
        for (int jLooper = 0; jLooper < kCellSize; jLooper++)
        {
            iterator(iLooper, jLooper);
        }
    }
}
-(void)\u loopOnCellWithIterator:(void(^)(int-iLooper,int-jLooper))迭代器
{
对于(int-iLooper=0;iLooper

因此,我想知道如何调用我设置的词典中的对象。

我不太确定你在问什么,但有两件事可能会有所帮助:

  • 您可以使用键访问字典中的值。方法
    -objectForKey:
    获取一个键并返回关联的对象。您应该知道键是什么,但是还有一个方法提供了一个包含所有键的数组

  • 如果您很难将网格坐标映射到字典键,可能是使用了错误的数据结构。数组可能更合适,因为它易于从坐标转换为索引