簡體   English   中英

隱式轉換失去整數精度:'unsigned long'到'int'-錯誤

[英]Implicit conversion loses integer precision: 'unsigned long' to 'int' - Error

我在這里看到了關於相同錯誤的一些問答,但是它們都沒有幫助。 我仍然遇到相同的錯誤。 我需要更改什么? 這就是我現在所擁有的。
錯誤與這條線有關: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

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

這是一個很好的解釋:

何時使用NSInteger與int

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM