0
我使用ImageDemo模板,它工作得很好,如果我從包中的圖像編碼,但是當我嘗試從我的應用程序中創建的目錄中加載它們時,我沒有運氣。iPad AQGridView不顯示我的UIImages不在捆綁
代碼:我使用的拉我知道的作品,因爲我在我的應用程序等地遍使用的圖像數據,我檢查了無當我設置的財產
- (AQGridViewCell *) gridView: (AQGridView *) aGridView cellForItemAtIndex: (NSUInteger) index
{
static NSString * PlainCellIdentifier = @"PlainCellIdentifier";
AQGridViewCell * cell = nil;
ImageDemoGridViewCell * plainCell = (ImageDemoGridViewCell *)[aGridView dequeueReusableCellWithIdentifier: PlainCellIdentifier];
if (plainCell == nil)
{
plainCell = [[[ImageDemoGridViewCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 200.0, 150.0)
reuseIdentifier: PlainCellIdentifier] autorelease];
plainCell.selectionGlowColor = [UIColor lightGrayColor];
}
NSString *fileName = [NSString stringWithFormat:@"%@/%@_tn.jpg",[manufacturerID stringValue], [[[self.collectionItems objectAtIndex:index] valueForKey:@"PhotoName"] stringByReplacingOccurrencesOfString:@" " withString:@"%20"]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *savePath =[documentsPath stringByAppendingPathComponent:fileName] ;
NSData *imageData = nil;
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:savePath];
if (fileExists) {
imageData = [NSData dataWithContentsOfFile:savePath];
} else {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"NoImageAvailableThumbNail" ofType:@"png"];
imageData = [NSData dataWithContentsOfFile:filePath];
}
UIImage *myImage = [UIImage imageWithData:imageData];
NSLog(@"%@", myImage);
if (myImage==nil) {
NSLog(@"NO IMAGE");
}
plainCell.image = myImage;
cell = plainCell;
return (cell);
}
我的代碼AQGridViewCell:
- (void) setImage: (UIImage *) anImage
{
_imageView.image = anImage;
[self setNeedsLayout];
}
非常感謝你的回答,我添加了日誌記錄,並且我絕對得到一個圖像:但他們只是不' t顯示。我一定在某個地方做了一些愚蠢的事情 - 我會繼續尋找和感謝。 –
Slee
2011-03-16 16:14:11
仍然堅持這個,我知道UIImage被創建並通過 - 我將它們添加到主視圖,因爲它作爲測試循環通過,他們肯定會加載。我可以從其他地方加載包含在該包中的圖像,包括來自URL的圖像。如果你能想到其他的東西,我會很感激 - 謝謝你的幫助。 – Slee 2011-03-21 22:26:49
要檢查的一件事就是圖像視圖的框架不是空矩形(即寬度/高度爲0.0)。它應該在'-layoutSubviews'中更新,因此請先在那裏檢查。此外,請檢查返回的UIImage是否有空或零大小(0.0x0.0),因爲這可能會導致相同類型的問題。 – 2011-03-21 23:57:32