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的*)
的位置是正在陣列中保持的夾具類。任何人都可以闡明它爲什麼這樣做嗎?如果您需要更多信息,請隨時提問。
丹尼斯