专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Iphone

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)];
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: