【发布时间】:2015-01-25 19:06:22
【问题描述】:
我收到此警告。不知道我需要做什么修复。 Objective-C 的新手。似乎不喜欢这条线,到达这条线后应用程序崩溃:
UIImageView *tmp = [[UIImageView alloc] initWithImage:[data objectAtIndex:index]];
我收到的警告:
/test/ViewController.m:186:89:指向整数转换的不兼容指针将“NSNumber *__strong”发送到“NSUInteger”类型的参数(又名“无符号长”)
ViewController.m 文件:
@interface ViewController () <UICollectionViewDataSource_Draggable, UICollectionViewDelegate>
{
NSMutableArray *data;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = (UICollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
NSNumber *index = [data objectAtIndex:indexPath.item];
for (UIView *subview in cell.subviews) {
if ([subview isKindOfClass:[UIImageView class]]) {
[subview removeFromSuperview];
}
}
UIImageView *tmp = [[UIImageView alloc] initWithImage:[data objectAtIndex:index]];
[cell addSubview:tmp];
return cell;
}
【问题讨论】:
-
为什么您的
data数组似乎同时包含NSNumber对象和UIImage对象?