在我的“connect4”风格游戏中,我有一个表示 7x6 网格的数组,数组中的每个“单元格”都包含 NSNull 或 UIView 子类“CoinView”。以下是从 NSMutableArray 和主视图中删除对象的正确方法吗?
- (IBAction)debugOrigin:(id)sender {
int x = 0;
int y = 0;
//get the coin object form the grid
CoinView *coin = [[grid objectAtIndex:x] objectAtIndex:y];
//cancel if there's no coin there
if ([coin isKindOfClass:[NSNull class]]) { return; }
//remove the coin from memory
[coin removeFromSuperview];
coin = nil;
[[grid objectAtIndex:x] setObject:[NSNull null] atIndex:y]; //will this leak?
}
谢谢!