0

画像の値パスを持つ配列があり、それらの画像をcollection viewセルに動的に表示したいと思います。しかし、私は例外を得ています。

私のコードは次のとおりです。

- (void)viewDidLoad
{
    [super viewDidLoad];


    data=[MyDatabase new];
    imagearray=[data OpenMyDatabase:@"SELECT pic_url FROM interior":@"pic_url"];


    gallerycollection.dataSource=self;
    [[self gallerycollection]setDelegate:self];
    gallerycollection.backgroundColor=[UIColor clearColor];
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier=@"Cell";
    customcell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
   // [[cell nyimage]setImage:[UIImage imageNamed:[imagearray objectAtIndex:indexPath.row]]];
    UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:1];
    recipeImageView.image=[imagearray objectAtIndex:indexPath.section * 1 + indexPath.row];
    return cell;

}

そして私は例外を得ています

2013-03-13 11:22:30.662 Home[3371:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[customcell setImage:]: unrecognized selector sent to instance 0x9f7e410

@ Mithun MP:これらは私のデータベースファイルです

MyDatabase.h

#import "FMDatabase.h"
@interface MyDatabase : NSObject
@property (strong,nonatomic) NSString *databaseName,*databasePath;
-(NSMutableArray *) OpenMyDatabase: (NSString *) query: (NSString *) column;
-(FMDatabase *)openDatabase: (NSString *)databasename;
-(NSMutableArray *) storeDatabaseColumnInArray: (FMDatabase *) database: (NSString *) sqlStatement: (NSString *) columnName;
@end


MyDatabase.m

#import "MyDatabase.h"
#import "FMDatabase.h"




@implementation MyDatabase



-(NSMutableArray *)OpenMyDatabase: (NSString *)query: (NSString *)column
{
    //store the database name here
    self.databaseName=@"App_Database.sqlite";

    //get the reference of the database to be stored in device or emulator
    FMDatabase *database=[self openDatabase: self.databaseName];

    //open the database
    [database open];

    //fetch a collumn from database and store it in array
   // NSArray *nsarr= [self storeDatabaseColumnInArray: database: @"select id from kas":@"id"];
    NSArray *nsarr= [self storeDatabaseColumnInArray: database: query: column];

    //close the database
    [database close];
    return nsarr;
}


- (FMDatabase *)openDatabase: (NSString *)databasename
{

    NSFileManager *fm = [NSFileManager defaultManager];
    NSString *documents_dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *db_path = [documents_dir stringByAppendingPathComponent: databasename ];
    NSString *template_path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: databasename];

    if (![fm fileExistsAtPath:db_path])
        [fm copyItemAtPath:template_path toPath:db_path error:nil];
    FMDatabase *db = [FMDatabase databaseWithPath:db_path];
    if (![db open])
        NSLog(@"Failed to open database!");
    return db;
}
-(void) createAndCheckDatabase
{
    BOOL success;

    NSFileManager *fileManager=[NSFileManager defaultManager];
    success=[fileManager fileExistsAtPath:_databasePath];
    NSString *databasePathFromApp=[[[NSBundle mainBundle] resourcePath]
                                   stringByAppendingPathComponent:self.databaseName ];
    [fileManager copyItemAtPath:databasePathFromApp toPath:_databasePath error:nil];

}

-(NSMutableArray *) storeDatabaseColumnInArray : (FMDatabase *) database: (NSString *) sqlStatement: (NSString *) columnName
{

    NSMutableArray *mutablearray = [NSMutableArray array];
    FMResultSet *results = [database executeQuery: sqlStatement];

    while([results next]) {

        NSString *rowValue = [results stringForColumn:columnName];

        [mutablearray addObject:results];
         NSLog(@"row value %@",rowValue);
    }

    //convert the nsmutable array to nsarray


    NSMutableArray *temparr=[NSMutableArray arrayWithArray:mutablearray];
       return temparr;


}

@end
4

1 に答える 1

0

この行が原因で問題が発生しています。

UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:1];

画像ビューではなく、カスタムセルにタグを設定していると思います。

于 2013-03-13T06:05:24.633 に答える