【问题标题】:How to display data from sqlite in UITableViewCell [closed]如何在 UITableViewCell 中显示来自 sqlite 的数据
【发布时间】:2013-04-28 13:44:06
【问题描述】:

我是 iphone 上 sqlite 的菜鸟,我学了几天。我在互联网和这个网站上搜索,对 sqlite 和使用它感到很困惑。 我有一个有很多价值的 json url。我想接收并解析一个特定的值并保存在 sqlite 中并从 UITableView 中的 sqlite 读取。

我解析 json 并将其保存在带有特定查询的 sqlite DB 中,但我不知道如何检索数据并显示它。 请用代码告诉我。 对不起,如果我的英语不好。

【问题讨论】:

  • 请不要负面评价...指导我!!!
  • 原生 sqlite api 对开发者不太友好,你可以试试FMDB。你可以找到一个很好的教程here

标签: ios objective-c json sqlite uitableview


【解决方案1】:

在这里查看我的答案:-

https://stackoverflow.com/posts/16322989/edit

希望对你有帮助

显示数组值使用此代码:

Now in the cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

     UITableViewCell *cell=[[UITableViewCell alloc]  initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    //Add the Bg Image to the cell
     //Add the Label
     UILabel *cellTitle=[[UILabel alloc]initWithFrame:CGRectMake(15, 7, 300, 30)];
     [cellTitle setBackgroundColor:[UIColor clearColor]];
     [cellTitle setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
     [cellTitle setTextColor:[UIColor darkGrayColor]];
     [cellTitle setText:[[array objectAtIndexPath:indexPath.row] objectForKey:@"Name"]];
     [cell.contentView addSubview:cellTitle];
     return  cell;

   }

也在numberOfRowsInSection中:

   -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section   
   {
       return [array count];
   }

【讨论】:

  • 我的朋友如何在 tableview 的数组中显示值?
  • 我更新了我的代码,希望它能解决你的问题。
【解决方案2】:

这里有一个 sqlite 检查的教程。这为 sqlite 制作了一个服装类,这对你有帮助。

http://www.xprogress.com/post-38-new-sqlite3-handling-library-for-iphones-and-cocoa-now-under-development/

【讨论】:

  • 链接似乎很旧。
  • 这很好......我也将此文件用于sqlite
  • 只是想确认一下,如果你真的尝试过。
  • 是的。我在上一个项目中使用这个文件,它仍然有效。
【解决方案3】:

在方法- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath中使用以下代码:

cell.textLabel.text = [ArrayName objectAtIndex:indexPath.row];

这可能对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    相关资源
    最近更新 更多