首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于SQLite3的基本IOS数据库应用程序

基于SQLite3的基本IOS数据库应用程序
EN

Stack Overflow用户
提问于 2014-08-25 04:25:50
回答 1查看 53关注 0票数 0

因此,我正在设计一个简单的应用程序来练习我的iOS开发技能,基本上我正在制作一个简单的数据库应用程序,其中包含不同类型的水果和蔬菜。我设法将整个数据库读入我的应用程序,并将其显示在TableView上,这正是我想要的。然而,我现在看到的是主页上所有的水果和蔬菜,大约有一千种。我想对列进行分组,并移到下一个表视图,因此,如果按下“水果表”行,我将继续使用一个新的TableView,它将显示所有(且仅)水果,以及蔬菜等。我知道我应该使用group,将所有独特的食物类型(例如水果、蔬菜、奶制品)分组,但不太确定如何使用它。如有任何帮助或建议,将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-25 05:23:57

好的,这可能是您想要的:

首先声明数据数组:

代码语言:javascript
复制
NSMutableArray *datasource;

datasource=[[NSMutableArray alloc]initWithObjects:@"Fruits",@"Vegetables", nil];

设置表中的行数:

代码语言:javascript
复制
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    // Return the number of rows in the section.
    return [datasource count];
}

向单元格输入数据:

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mycell" forIndexPath:indexPath];
    cell.textLabel.text=[datasource objectAtIndex:indexPath.row];

    // Configure the cell...

    return cell;
}

您真正需要做的是在这里准备segue方法:

代码语言:javascript
复制
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    DestinationVC *destVC = segue.destinationViewController;
    UITableViewCell *cell=[myTable cellForRowAtIndexPath:path];
    destVC.selectedFoodType=cell.textLabel.text;
    //This will pass what type of food you selected and pass it to the second tableview. Then there you can build the logic to populate table cells according to selected food type


}

注意:通过情节提要将单元格连接到另一个视图控制器。我相信你知道如何:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25479026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档