1
我在将一个自定义类和UIImage视图混合在一个数组中时遇到了一些问题。这些都存储在阵列中,我正在使用:对象类型更改
if ([[fixtures objectAtIndex:index] isKindOfClass:[Fixture class]])
以区分它是否是UIIMage或Fixture对象。为此我的源代码是:
- (void) moveActionGestureRecognizerStateChanged: (UIGestureRecognizer *) recognizer
{
switch (recognizer.state)
{
case UIGestureRecognizerStateBegan:
{
NSUInteger index = [fixtureGrid indexForItemAtPoint: [recognizer locationInView: fixtureGrid]];
emptyCellIndex = index; // we'll put an empty cell here now
// find the cell at the current point and copy it into our main view, applying some transforms
AQGridViewCell * sourceCell = [fixtureGrid cellForItemAtIndex: index];
CGRect frame = [self.view convertRect: sourceCell.frame fromView: fixtureGrid];
dragCell = [[FixtureCell alloc] initWithFrame: frame reuseIdentifier: @""];
if ([[fixtures objectAtIndex:index] isKindOfClass:[Fixture class]]) {
Fixture *newFixture = [[Fixture alloc] init];
newFixture = [fixtures objectAtIndex:index];
dragCell.icon = [UIImage imageNamed:newFixture.fixtureStringPath];
[newFixture release];
} else {
dragCell.icon = [fixtures objectAtIndex: index];
}
[self.view addSubview: dragCell];
}
}
然而,拖着那类灯具的目标单元格时,我会得到错误,如EXC_BAD_ACCESS或无法识别的选择发送到实例(这是有道理的,因为它是发送。CALayerArray规模命令
因此,我设置一个断点,看灯具阵列内这里我看到UIImages都设置为正确的类类型,但也有:
- (CALayerArray *)
- (夹具*)
- (NSObject的*)
的位置是正在阵列中保持的夹具类。任何人都可以阐明它为什么这样做吗?如果您需要更多信息,请随时提问。
丹尼斯