2
我见过几个Q & A在这里讲述了同样的错误,但没有一个是有帮助的。我仍然遇到同样的错误。我需要改变什么?这就是我现在所拥有的。
错误与此行有关:imageIndex =(imageIndex < 0)? ([图像计数] -1):
感谢您的帮助!隐式转换失去了整数精度:'unsigned long'为'int' - 错误
#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
这是Objective-C的? (因为肯定不是C++) – 2014-10-20 16:56:33
对不起,错误的标签。它实际上是objective-c – Max1980 2014-10-20 16:58:00
查看'NSArray count'的文档。看到它的返回值?使用'imageIndex'变量而不是'int'使用相同的数据类型。 – rmaddy 2014-10-20 17:05:38