加载 UITableView 时出现问题
您好,我在使用 SQLite 加载 UITableView 时遇到问题。我有这个代码!
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 我有这个函数:
-(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 *)[[UIApplication sharedApplication] delegate];
DBModel *models = (DBModel *)[appDelegate.aryModel objectAtIndex:indexPath.row];
cell.textLabel.text = models.model;
cell.detailTextLabel.text = [models.avaliable stringValue];
return cell;
我的问题是:
我无法及时从数据库值 NSInteger 中获取整数值来播放,它们总是带来零,并且数据库中有值对于专栏。
当我尝试使用字幕样式上传 UITableView 并播放从数据库获取的 myvariable 的值时,它不会添加任何内容,也不会添加任何格式,从而带来法线。
我想做以下事情:
根据上面提到的我的数据库结构,我填写一个详细的 UITableView,其中包含图像、标题和标题(如果可能的话,根据值添加图片标题或星星)即可并通过单击通话详细信息在线完成。
谢谢
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 *)[[UIApplication 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您的 readModeDatabase 函数有问题。当从数据库中读取记录时,引用的列从 0 开始(与从 1 开始的存储/更新相比,这很奇怪),上面的行读取 1,因此从数据库中读取的实际上是第二列而不是第一列。因此,要按照以下方式从数据库读取 modelID你的数据库结构你应该这样读:
此外,NSInteger 只是长整型的同义词,NSNumber 是目标 c 类。所以 NSInteger 不应该有 (NSInteger *) 这样的指针。有关更多说明,请访问 http://iosdevelopertips.com/cocoa/nsnumber-and-nsinteger。 html
并根据需要在课堂上的所有地方和其他地方更正相同的内容。
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
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.