iphone把sqlite中的数据显示到页面中?该如何处理
发布时间:2010-05-30 01:26:30 文章来源:www.iduyao.cn 采编人员:星星草
iphone把sqlite中的数据显示到页面中?
我建了这样的两个页面,首页(1号页面)有个按钮能点击能连接到另一个页面(2号页面),在2号页面里写入数据,保存在sqlite中 ,我想在首页把存储在sqlite中数据显示出来,怎么就不显示呢 ,像这样的显示数据要注意什么么?我把首页的代码都粘过来。不知道问答这里能不能上传个压缩文件呢?以下是代码,请各位前辈指点。[code=C/C++][/code]
#import "SQL_DemoViewController.h"
#import "User.h"
#import "ResultViewcontroller.h"
@implementation SQL_DemoViewController
@synthesize resultViewController;
@synthesize addNavigationController;
@synthesize dataView;
-(NSString*)databasePath
{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *pathname = [path objectAtIndex:0];
return [pathname stringByAppendingPathComponent:DataFile];
}
-(id)initWithDelegate:(id)delegate
{
if (self = [super init]) {
}
return self;
}
- (void)loadView
{
[super loadView];
self.view.backgroundColor = [UIColor whiteColor];
dataView=[[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 400.0) style:UITableViewStylePlain];
self.dataView.delegate=self;
self.dataView.dataSource=self;
dataView.separatorColor=[UIColor lightGrayColor];
[self.view addSubview:dataView];
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle: @"new" style:UIBarButtonItemStyleBordered target:self action:@selector(addView)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self getToTalCount];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =@"CellIdentifier";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
}
User *user=[self getUser:[indexPath row]+1];
cell.textLabel.text=[NSString stringWithFormat:@"%@ | %@ ",user.id,user.detail];
return cell;
}
-(void)addView
{
ResultViewcontroller *controller = self.resultViewController;
if (addNavigationController == nil) {
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
self.addNavigationController = navController;
[navController release];
}
ResultViewcontroller *resultViewcontroller = [[ResultViewcontroller alloc] initWithDelegate:self];
[self.navigationController pushViewController:resultViewcontroller animated:YES];
}
-(User*)getUser:(int)id
{
if(sqlite3_open([[self databasePath] UTF8String],&database)!=SQLITE_OK)
{
sqlite3_close(database);
NSAssert(0,@"open database faild!");
return nil;
}
User *user=[[User alloc] init];
NSString *countSQl=[NSString stringWithFormat:@"SELECT ROW,DETAIL FROM UsrTable WHERE ROW=%i",id];
sqlite3_stmt *statement;
if(sqlite3_prepare_v2(database,[countSQl UTF8String],-1,&statement,nil)==SQLITE_OK)
{
while(sqlite3_step(statement)==SQLITE_ROW)
{
user.id=[NSString stringWithFormat:@"%d",sqlite3_column_int(statement,0)];
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
图片拾取器问题
用图片拾取器方法除了能拾取相册里面的图片外,能不能拾取其它文件里面非照片的图像啊,如果能,要怎么做
------解决...
-
请教个问题。。很弱智,不要嘲笑。。
请问mac osx 10.6下开发出来的程序在mac osx 10.5下可以正常使用么?会不会有些库的问题?
客户要...
-
一个数组可以放UIButton,那怎么调用这些元素呢,[array objectatindex i]不好用]
UIButton,那怎么调用这些元素呢,[array objectatinde...
-
关于imageView显示图片的问题
我现在需要在一个imageView中现在两张图片,这两张是重叠显示的,在android中,我这么做到的,imageView1.s...
-
如何在软件中嵌套ppt播放功能
如何在软件中嵌套ppt播放功能 不知道这个能实现吗
------解决方案--------------------
可以,...
-
objectivc-c
请问下自学obj-c要看哪本书比较好?
linux下可以运行obj-c的程序吗?
mac软件开发除了obj-c还需要什么别的吗?
------解...
-
怎么实现iphone客户端软件与服务器端的数据交互?
怎么实现iphone客户端软件与服务器端的数据交互?
------解决方案---------------...
-
求IOS微信界面实现思路
如题,请大神们指点一二,非常感谢!
------解决方案--------------------
问题过于笼统,无法作答
------解决...
-
给黑苹果搞个Navicat for SQLite 求个下载地址
给黑苹果搞个Navicat for SQLite 求个下载地址 谢谢
------解决方案---------...
-
iphone中按提示弄音频接收, 在线等
关于iphone中的音频接收( Streaming Live or On-Demand Video from IIS7 to iOS Devices (iPhon...