Ios 隐式转换丢失整数精度:';无符号长';至';int';-错误

Ios 隐式转换丢失整数精度:';无符号长';至';int';-错误,ios,objective-c,cocoa-touch,uikit,Ios,Objective C,Cocoa Touch,Uikit,我在这里看到了一些关于相同错误的问答,但没有一个是有用的。我还是会犯同样的错误。我需要改变什么?这就是我现在得到的错误与此行有关:imageIndex=(imageIndex

我在这里看到了一些关于相同错误的问答,但没有一个是有用的。我还是会犯同样的错误。我需要改变什么?这就是我现在得到的
错误与此行有关:imageIndex=(imageIndex<0)?([图像计数]-1):
谢谢你的帮助

#import "Photogallery.h"

@interface Photogallery ()


@end

@implementation Photogallery
@synthesize imageView;
int imageIndex = 10;

- (void)viewDidLoad {
[super viewDidLoad];


}
- (IBAction)handleSwipe:(UIGestureRecognizer *)sender {

NSArray *images=[[NSArray alloc]initWithObjects:@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg",@"6.jpg",@"7.jpg",@"8.jpg",@"9.jpg",@"10.jpg", nil];

UISwipeGestureRecognizerDirection direction = [(UISwipeGestureRecognizer *)sender direction];

switch (direction) {
    case UISwipeGestureRecognizerDirectionLeft:
        imageIndex++;
        break;
    case UISwipeGestureRecognizerDirectionRight:
        imageIndex--;
        break;

    default:
        break;
}
imageIndex = (imageIndex < 0) ? ([images count] -1):
imageIndex % [images count];
imageView.image = [UIImage imageNamed:[images objectAtIndex:imageIndex]];
}


@end
#导入“Photogallery.h”
@界面照片库()
@结束
@实现照片库
@综合图像视图;
int-imageIndex=10;
-(无效)viewDidLoad{
[超级视图下载];
}
-(iAction)无手柄擦除:(UIgestureRecognitor*)发送器{
NSArray*images=[[NSArray alloc]initWithObjects:@“1.jpg”,“2.jpg”,“3.jpg”,“4.jpg”,“5.jpg”,“6.jpg”,“7.jpg”,“8.jpg”,“9.jpg”,“10.jpg”,nil];
UISweepGestureRecognitzerDirection=[(UISweepGestureRecognitzer*)发送方方向];
开关(方向){
案例UISweepGestureRecognitizerDirectionLeft:
imageIndex++;
打破
案例UISweepGestureRecognitizerDirectionRight:
图像索引--;
打破
违约:
打破
}
imageIndex=(imageIndex<0)?([图像计数]-1):
imageIndex%[图像计数];
imageView.image=[UIImage ImageName:[images objectAtIndex:imageIndex]];
}
@结束

在Objective-C代码中使用NSInteger,而不是int

这里有一个很好的解释:


这个目标是c吗?(因为不是C++肯定)对不起,错误的标签。事实上,这是客观的——查看文档中的
NSArray count
。看到它的返回值了吗?对
imageIndex
变量使用相同的数据类型,而不是
int
。Maddy的答案是正确的。您是否已将所有警告设置为错误,因为这通常只是编译器警告?使用NSInteger not int会导致错误。KirkSpaziani有很多