ImageDemoテンプレートを使用していますが、バンドルのイメージをコード化するとうまくいきますが、アプリで作成したディレクトリからロードしてみると運がありません。iPad AQGridViewにバンドルではないUIImagesが表示されない
コード:私は私のアプリでは他の場所ですべての上にそれを使用して、私は上のプロパティを設定するときに私がnilをチェックしていますので、私は、私は作品を知っている画像データをプルするために使用しています
- (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);
}
IコードAQGridViewCell:
- (void) setImage: (UIImage *) anImage
{
_imageView.image = anImage;
[self setNeedsLayout];
}
私はロギングを追加しました。私は間違いなく画像を取得しました:しかし、 tショー。私はどこかで愚かなことをしたにちがいありません。 –
Slee
これに依っても、私はUIImageが作成され、渡されたことを知っています - テストとしてループしている間、メインビューに追加しました。私はバンドルに含まれる画像を、URLからの他の場所からロードすることはできません。あなたが他の何かを考えることができるなら、私はそれを感謝します - 助けに感謝します。 – Slee
画像ビューのフレームが空の矩形(幅/高さ0.0)でないことを確認してください。 '-layoutSubviews'で更新されているはずですので、最初に確認してください。また、同じ種類の問題を引き起こす可能性があるので、返されたUIImageが空または無限のサイズ(0.0x0.0)を持っているかどうかを確認してください。 –