【问题标题】:Get states of a country when a country is selected [closed]选择一个国家时获取一个国家的状态[关闭]
【发布时间】:2012-11-06 10:40:17
【问题描述】:

我有一个显示所有国家/地区的代码,我们可以从中选择一个特定的国家/地区。我现在想要的是当我选择一个国家时,我想查看该国家/地区的州列表。有人可以帮我吗?有它的方法或API吗?任何帮助表示赞赏。 谢谢

【问题讨论】:

    标签: iphone ios ios5 ios4 ios6


    【解决方案1】:

    使用db 获取countries and its states。就download吧。

    现在使用这个数据库进行如下查询:

    NSString *queryString = [NSString stringWithFormat:@"select zone_id , name from
                       zone where country_id = %d", countryID]; //here countryID is country code
    

    EDIT :获取所有具有这样查询的国家/地区:

    NSString *queryStrAllCountries = [NSString stringWithFormat:@"select name from
                       countries"]; 
    

    从使用这样的查询选择的国家/地区获取 countryID:

     NSString *queryStrCountry = [NSString stringWithFormat:@"select country_id from
                       countries where name='%@'", countryName]; //provide country name selected
    

    参考this答案,提供的信息相同。

    【讨论】:

    • 但它显示 countryID 未声明。
    • 这里的 countryID 是苹果标准中定义的数字。见数据库
    【解决方案2】:

    这取决于您实施解决方案的方式。我假设您使用的是UITableView。

    那么最好的方法是将UINavigationController 设置为rootViewController(在Interface Builders 主笔尖中)并使用UITableViewController 视图作为UINavigationController 的根视图。然后在第一个表格的一行被制表符时推送另一个UITableViewController。

    如果您已经掌握了一些关于 UINavigationController 的信息,这几行可能会对您有所帮助:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
        [self.navigationController pushViewController:detailViewController animated:YES];
    }
    

    如果您正在寻找有关 UINavigationBar 和 UITableView 的教程,请查看 here。如果您想自己搜索教程,请搜索UITableView detail view。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-01
      • 1970-01-01
      • 2013-02-27
      • 1970-01-01
      相关资源
      最近更新 更多