gpt4 book ai didi

ios - 使用 SQLite3 的基本 IOS 数据库应用程序

转载 作者:行者123 更新时间:2023-11-29 02:43:14 24 4
gpt4 key购买 nike

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

最佳答案

好吧,这可能就是你想要的:

首先声明数据数组:

NSMutableArray *datasource;

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

设置表格的行数:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

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

向单元格输入数据:

- (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方法中:

- (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


}

注意:通过 Storyboard 将单元格中的 Segue 连接到另一个 View Controller 。我相信你知道怎么做:)

关于ios - 使用 SQLite3 的基本 IOS 数据库应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25479026/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com