【代码笔记】先选择城市,然后,跳转Tabbar

一,效果图。

二,工程图。

三,代码。

ChooseCityViewController.h

#import <UIKit/UIKit.h>

@interface ChooseCityViewController : UIViewController
<UITableViewDelegate,UITableViewDataSource>
{
    NSMutableArray * dataArray;
    UITableView * mTableView;
}

@end

ChooseCityViewController.m

#import "ChooseCityViewController.h"
#import "DetailViewController.h"

@interface ChooseCityViewController ()

@end

@implementation ChooseCityViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    //读取plist文件
    [self readPlistFile];
    //初始化tableView
    [self initTableView];

}
#pragma -mark -functions

-(void)readPlistFile
{
    dataArray = [[NSMutableArray alloc] initWithCapacity:0];
    NSString * path = [[NSBundle mainBundle] pathForResource:@"city" ofType:@"plist"];

    NSDictionary * dict = [[NSDictionary alloc] initWithContentsOfFile:path];
    NSEnumerator * enumerator = [dict keyEnumerator];
    NSString * key;
    while (key = [enumerator nextObject]) {
        NSDictionary * t = [dict objectForKey:key];

        [dataArray addObject:t];
    }
    NSLog(@"%@",dataArray);
}

-(void)initTableView
{
    mTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    mTableView.delegate = self;
    mTableView.dataSource = self;
    mTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:mTableView];

}
#pragma -UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [dataArray count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * ID = @"cellID";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    NSDictionary *dict = [dataArray objectAtIndex:indexPath.row];
    cell.textLabel.text = [dict objectForKey:@"city_name"];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary * dict = [dataArray objectAtIndex:indexPath.row];
    //把所选择的城市保存到本地
    [[NSUserDefaults standardUserDefaults] setObject:[dict objectForKey:@"city_id"] forKey:@"city_id"];
    [[NSUserDefaults standardUserDefaults] setObject:[dict objectForKey:@"city_name"] forKey:@"city_name"];

    //跳转到另一个有tabbar的页面
    DetailViewController *detail=[[DetailViewController alloc]init];
    [self.navigationController pushViewController:detail animated:NO];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

时间: 2024-08-10 00:07:00

【代码笔记】先选择城市,然后,跳转Tabbar的相关文章

【代码笔记】iOS-动画的跳转

一,工程图. 二,代码. //点击任何处跳转到页面 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CATransition* animTrans = [CATransition animation] ; animTrans.type = kCATransitionFade; animTrans.duration = 1; animTrans.timingFunction =[CAMediaTimingFunct

1.选择城市

项目介绍 应用截图 主要功能 写的一个APP总结一下 使用车联网api解析天气数据并展示在界面 定位 通知栏 桌面小部件 动态添加删除城市并显示在界面上方便查看 选择城市界面 首先我网上找了个城市json数据信息,然后自己做了个json数据存放在res的raw目录下 然后需要解析出来存放在数据库中,不用每次都去解析json CoolWeatherOpenHelper public class CoolWeatherOpenHelper extends SQLiteOpenHelper { /**

美团HD(5)-选择城市

DJSelectCityViewController.m #import "DJSelectCityViewController.h" #import "DJConstantValue.h" #import "DJCityGroup.h" #import "MJExtension.h" @interface DJSelectCityViewController ()<UITableViewDataSource,UITab

选择城市列表的小Demo

先上源码: 选择城市列表的小Demo 选择城市列表的小Demo,布布扣,bubuko.com

winform 实现选择城市列表

先上图 #region 选择城市 /// <summary> /// 点击字母事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void item_Click(object sender, EventArgs e) { LinkLabel lbl = sender as LinkLab

多线程二(GCD)代码笔记

// // TWFXViewController.h // Demo_GCD // // Created by Lion User on 12-12-11. // Copyright (c) 2012年 Lion User. All rights reserved. // #import <UIKit/UIKit.h> @interface TWFXViewController : UIViewController @property (retain, nonatomic) IBOutlet

每天一个JavaScript实例-动态省份选择城市

<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>每天一个JavaScript实例-动态省份选择城市</title> <script> var citystore = new Array(); citystore = [[

select省市联动选择城市 asp.net mvc4

本文在 http://www.cnblogs.com/darrenji/p/3606703.html(感谢博主的分享)基础上加入全国各省市,从文件中读取全国省市县,组成省市联动的选择标签 在Model里定义Province 和 City ? 1 2 3 4 5 6 7 8 9 10 11 12 13 public class Province {     public int ID { get; set; }     public string Name { get; set; } } publ

Objective-C学习笔记(八)——高级跳转语句goto使用方法

在我们学习C语言的时候,碰到一种程序跳转,叫做goto,goto可以跳到程序的任意地方.又到了后来,学习了程序设计方法学,不知哪一位计算机前辈(貌似是迪杰斯特拉),认为goto使得程序的跳转过于随意,使代码的逻辑变得混乱,所以不推荐使用goto.现在来到OC,在OC中也有goto,为了学习的完整性,我们也来学习下这种相对高级的跳转. (一)代码一: int main(int argc, const char * argv[]) { @autoreleasepool { int a=0; star

原创控件代码共享--日期选择控件

思路:实现日期年月日的选择 1.可以设定年的起止年份 2.排除不正确日期选择的可能 3.使用javascript实现控制 4.使用Text属性方便获取设置日期值 ================================= 代码如下: using System; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.IO; using