开发者

Problem load UITableView

开发者 https://www.devze.com 2023-03-01 05:01 出处:网络
Hi I\'m problem in load UITableView using SQLite. I have this code! DataBase Struct: modelID integer PK autoincrement

Hi I'm problem in load UITableView using SQLite. I have this code!

DataBase Struct:

modelID integer PK autoincrement
model varchar
avaliable int
image1 blob
image2 blob
image3 blob

.H

#import <UIKit/UIKit.h>
@interface DBModel : NSObject {
     NSNumber *modelID;
        NSString *model;
     NSNumber *avaliable;
}

@property (nonatomic, retain) NSNumbe *modelID;
@property (nonatomic, retain) NSString *model;
@property (nonatomic, retain) NSNumbe *avaliable;

-(id)initWithName:(NSString *)n modelID:(NSInteger *)mid avaliable:(NSNumber *)aval;

@end

.M

#import "DBModel.h"

@implementation DBModel
@synthesize modelID, model, avaliable;

-(id)initWithName:(NSString *)n modelID:(NSInteger *)mid avaliable:(NSInteger *)aval {
     self.name = n;
     self.modelID= mid;
     self.avaliable= aval ;
     return self;
}
@end

AppDelegate I have this function:

-(void) readModeDatabase {

     sqlite3 *database;
     aryModel = [[NSMutableArray alloc] init];
     if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
          const char *sqlStatement = "select * from models";

          sqlite3_stmt *compiledStatement;
          if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {

               while(sqlite3_step(compiledStatement) == SQLITE_ROW) {

                    NSInteger *aModelID = sqlite3_column_int(compiledStatement, 1);

NSString *aModel = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];                     NSInteger *aAvaliable = sqlite3_column_int(compiledStatement, 3);
                                //Here I need load on image  in my DBModel.

                    // Create a new animal object with the data from the database
                    DBModel *model = [[DBModel alloc] initWithName:aMode modelID:aModelID avaliable:aAvaliable];

                    [aryModel addObject:model];

                    [model  release];
               }
          }
          sqlite3_finalize(compiledStatement);

     }
     sqlite3_close(database);
}

Event cellForRowAtIndexPath

// Set up the cell
DBModelAppDelegate *appDelegate = (DBModelAppDelegate *)[[UIApplicati开发者_运维知识库on sharedApplication] delegate];
DBModel *models = (DBModel *)[appDelegate.aryModel objectAtIndex:indexPath.row];
cell.textLabel.text = models.model;
cell.detailTextLabel.text = [models.avaliable stringValue];

return cell;

My problem is:

I'm having problem in time to bring an integer value from the database values ​​NSInteger to play, they always bring zero, and the database there are values ​​for the column.

When I try to upload a UITableView using Subtitle style and playing the value of myvariable obtained from the database it adds nothing and no format, bringing a normalline.

I'd like to do the following:

According to my database structure mentioned above, I fill out a detailed UITableView,with an image, title and a caption (if possible a picture caption or stars according to the value) is all that needs to be done And to complete online by clicking the call details.

Thanks


I believe you have problem in readModeDatabase function. While reading records from database referencing of columns starts from 0 (its weird compare to storing/updating which starts from 1), above line reads 1 so from database it is reading 2nd column actually instead of first.So to read modelID from database as per your database structure you should read it like

 NSInteger aModelID = sqlite3_column_int(compiledStatement, 0);

Further more to this NSInteger is just synonym to long integer and NSNumber is objective c class. So NSInteger should not have pointer as (NSInteger *). For more clarification visit http://iosdevelopertips.com/cocoa/nsnumber-and-nsinteger.html

And also correct the same at all the places in class and other places as needed.

(NSInteger *) to (NSInteger)
0

精彩评论

暂无评论...
验证码 换一张
取 消