IOS实现选择城市后跳转Tabbar效果

 更新时间:2016年07月06日 09:22:52   作者:情深雨蒙  
这篇文章主要为大家详细介绍了IOS实现选择城市后跳转Tabbar效果的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了IOS选择城市后跳转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.
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • iOS 进度条、加载、安装动画的简单实现

    iOS 进度条、加载、安装动画的简单实现

    这篇文章主要介绍了iOS 进度条、加载、安装动画的简单实现,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2017-03-03
  • iOS实现一个可以在屏幕中自由移动的按钮

    iOS实现一个可以在屏幕中自由移动的按钮

    经常在手机上看到可以随意移动的按钮,正巧最近工作遇到了这个需求,索性就写一个,下面这篇文章主要给大家介绍了利用iOS实现一个可以在屏幕中自由移动的按钮的相关资料,需要的朋友可以参考借鉴,下面来一起看看吧。
    2017-07-07
  • 简单实现iOS指纹解锁(TouchID)

    简单实现iOS指纹解锁(TouchID)

    这篇文章主要介绍了如何简单实现iOS指纹解锁,验证TouchID,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-02-02
  • iOS中json解析出现的null,nil,NSNumber的解决办法

    iOS中json解析出现的null,nil,NSNumber的解决办法

    在iOS开发过程中经常需要与服务器进行数据通讯,Json就是一种常用的高效简洁的数据格式,通过本文给大家介绍iOS中json解析出现的null,nil,NSNumber的解决办法,感兴趣的朋友参考下
    2016-01-01
  • iOS动画之向右拉的抽屉3D效果

    iOS动画之向右拉的抽屉3D效果

    首先说下,其实一切的动画都是假象,3D效果也是这样.本篇我们来做一个这样的特效.来跟着小编一起学习学习。
    2016-08-08
  • iOS长按UIlabel实现可复制功能

    iOS长按UIlabel实现可复制功能

    在我们日常的开发中经常会遇到一些小需求,比如需要长按控件来拷贝控件中得内容,所以这篇文章跟大家分享下iOS中长按UIlabel实现可复制功能的方法,有需要的朋友们可以参考借鉴。
    2016-09-09
  • IOS如何在Host App 与 App Extension 之间发送通知

    IOS如何在Host App 与 App Extension 之间发送通知

    这篇文章主要介绍了IOS如何在Host App 与 App Extension 之间发送通知 的相关资料,需要的朋友可以参考下
    2016-03-03
  • iOS中tableview 两级cell的展开与收回的示例代码

    iOS中tableview 两级cell的展开与收回的示例代码

    本篇文章主要介绍了iOS中tableview 两级cell的展开与收回的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-03-03
  • iOS中设置view圆角化的四种方法示例

    iOS中设置view圆角化的四种方法示例

    最近因为工作的原因,遇到view圆角优化的问题,所以将实现的几种方法总结分享出来,下面这篇文章主要给大家介绍了关于iOS中设置view圆角化的四种方法,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴,下面随着小编来一起学习学习吧。
    2017-09-09
  • iOS 导航栏无缝圆滑的隐藏 Navigationbar实例代码

    iOS 导航栏无缝圆滑的隐藏 Navigationbar实例代码

    本文通过实例代码给大家介绍了iOS 导航栏无缝圆滑的隐藏 Navigationbar的效果,代码简单易懂,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2017-11-11

最新评论