0
我希望有人能幫助我在這裏,我不知道還能做什麼。我有一個UIScrollView加載一組44個圖像,然後允許用戶通過它們進行翻頁。我的代碼正在工作,然後突然停止。我不知道我已經改變,因此任何幫助,將不勝感激:加載圖像到一個UIScrollView
以前的觀點是一個UITableView,它被選爲該單元的名稱一起傳遞的字符串。下面是從滾動型viewDidLoad方法:
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Answer"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(answerPressed:)];
self.navigationItem.rightBarButtonItem = rightButton;
if([questionSetName isEqualToString:@"Limitations"]){
[self limitationsView];
}
}
這裏是limitationsView:
-(void)limitationsView{
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, -44, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
NSArray *unsortedArray = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:@"Images/Limitations"];
NSMutableArray *limitationImages = [[NSMutableArray alloc] init];
for (int x = 0; x<[unsortedArray count]; x++) {
NSString *fileName = [[unsortedArray objectAtIndex:x] lastPathComponent];
[limitationImages insertObject:fileName atIndex:x];
}
NSArray *sortedArray = [limitationImages sortedArrayUsingFunction:finderSortWithLocal
context:(__bridge void *)([NSLocale currentLocale])];
for(int i = 0; i< [sortedArray count]; i++){
CGFloat xOrigin = i * self.view.bounds.size.width;
UIImageView *limitationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];;
[limitationImageView setImage:[UIImage imageNamed:[sortedArray objectAtIndex:i]]];
limitationImageView.contentMode = UIViewContentModeScaleAspectFit;
[scroll addSubview:limitationImageView];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * [sortedArray count], self.view.frame.size.height);
[self.view addSubview:scroll];
}
當我到了LimitationsView方法sortedArray包含所有44個圖像的結束,以及適當的名稱,如果我嘗試設置scrollview的背景顏色,我可以成功地做到這一點。但我的圖像沒有加載,我爲什麼不知所措?
我會建議使用的NSLog(@「的形象:%@」,[ UIImage imageNamed:[limitsArray objectAtIndex:i]]);以查看圖像是否在該點處爲空。如果是這樣的話,那麼,這是您存儲數組中即串的問題,他們是不相同的,以您的圖片的實際名稱 – geraldWilliam
謝謝你 - 你是正確的,日誌確實顯示爲無,這個問題有去處理我正在使用的路徑。一旦我更新到正確的路徑,一切都完美無缺。 -乾杯 – Nathan