iOS UI08_TableView界面传值
实现两个界面之间内容的传递
//
// MainViewController.m
// UI08_TableView界面传值
//
// Created by dllo on 15/8/7.
// Copyright (c) 2015年 zhozhicheng. All rights reserved.
//
#import "MainViewController.h"
#import "SecondViewController.h"
@interface MainViewController ()<UITableViewDataSource,UITableViewDelegate,SecondViewControllerDelegate>
@property(nonatomic,retain)NSMutableArray *arr;
@property(nonatomic,retain)UITableView *tableView;
@property(nonatomic,retain)UIImageView *imageView;
@end
@implementation MainViewController
-(void)dealloc
{
[_arr release];
[_imageView release];
[_tableView release];
[super dealloc];
}
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self =[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.arr = [NSMutableArray arrayWithObjects:@"宋江", @"卢俊义", @"吴用", @"公孙胜", @"关胜", @"林冲", @"秦明" ,@"呼延灼" , @"花容",@"柴进", @"李应", @"朱仝",@"鲁智深",@"武松",nil];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationController.navigationBar.translucent=NO;
self.navigationItem.title=@"表视图";
self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
self.tableView.backgroundColor=[UIColor yellowColor];
[self.view addSubview:self.tableView];
[self.tableView release];
self.tableView.rowHeight=50;
self.tableView.dataSource=self;
self.tableView.delegate=self;
self.imageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"h1.jpeg"]];
self.imageView.frame=CGRectMake(0, -200, self.view.frame.size.width, 200);
//给tableview加入头视图
//宽是tableview的宽度
// self.tableView.tableHeaderView=self.imageView;
[self.tableView addSubview:self.imageView];
self.tableView.contentInset=UIEdgeInsetsMake(200, 0, 0, 0);
}
#pragma mark tableview的delegate已经签订好scrollerView的协议,仅仅要设置代理人,就能够使用scrollerview的协议方法
//仅仅要滑动就会触发
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//获取偏移量
CGFloat y=scrollView.contentOffset.y;
NSLog(@"%g",y);
if (y<0) {
self.imageView.frame=CGRectMake(0, y, self.view.frame.size.width, -y);
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuse=@"reuse";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:reuse];
if (!cell) {
cell =[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
}
cell.textLabel.text=self.arr[indexPath.row];
cell.detailTextLabel.text=[NSString stringWithFormat:@"%ld",indexPath.section];
cell.imageView.image=[UIImage imageNamed:@"天平.png"];
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"水浒";
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return self.arr;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SecondViewController *secVC=[[SecondViewController alloc] init];
secVC.name= self.arr[indexPath.row];
[self.navigationController pushViewController:secVC animated:YES];
[secVC release];
//
secVC.delegate=self;
}
-(void)changeValue:(NSString *)value
{
//属性的数组,相当于数据源,把传过来的值加入到数组中
[self.arr addObject:value];
//对数据进行刷新
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
//
// SecondViewController.h
// UI08_TableView界面传值
//
// Created by dllo on 15/8/7.
// Copyright (c) 2015年 zhozhicheng. All rights reserved.
//
#import <UIKit/UIKit.h>
@protocol SecondViewControllerDelegate <NSObject>
//协议方法
-(void)changeValue:(NSString *)value;
@end
@interface SecondViewController : UIViewController
@property(nonatomic,copy)NSString *name;
@property(nonatomic,assign)id<SecondViewControllerDelegate>delegate;
@end
//
// SecondViewController.m
// UI08_TableView界面传值
//
// Created by dllo on 15/8/7.
// Copyright (c) 2015年 zhozhicheng. All rights reserved.
//
#import "SecondViewController.h"
@interface SecondViewController ()
@property(nonatomic,retain)UILabel *label;
@property(nonatomic,retain)UITextField *textfield;
@property(nonatomic,retain)UIButton *button;
@end
@implementation SecondViewController
-(void)dealloc
{
[_label release];
[_textfield release];
[_button release];
[_name release];
[super dealloc];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor cyanColor];
self.label=[[UILabel alloc] initWithFrame:CGRectMake(100, 100, 150, 40)];
self.label.backgroundColor=[UIColor redColor];
self.label.layer.borderWidth=1;
self.label.layer.cornerRadius=10;
[self.view addSubview:self.label];
//赋值
self.label.text=self.name;
[self.label release];
self.textfield=[[UITextField alloc] initWithFrame:CGRectMake(100, 200, 150, 40)];
self.textfield.layer.borderWidth=1;
self.textfield.layer.cornerRadius=10;
[self.view addSubview:self.textfield];
[self.textfield release];
self.button=[UIButton buttonWithType:UIButtonTypeSystem];
self.button.frame=CGRectMake(200, 300, 150, 30);
[self.button setTitle:@"返回" forState:UIControlStateNormal];
[self.view addSubview:self.button];
self.button.layer.borderWidth=1;
self.button.layer.cornerRadius=5;
[self.button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)click:(UIButton *)button
{
[self.delegate changeValue:self.textfield.text];
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
iOS UI08_TableView界面传值的更多相关文章
- iOS开发- 界面传值(1)-通知模式(广播)
之后的几篇博客, 记录下不同界面间传值的经常使用办法. 这篇文章记录广播的方式. iOS的设计模式中,通知模式也是当中重要的模式之中的一个,Notification直译为通知,事实上本人认为叫做广播模 ...
- 新手介绍简单一下iOS开发中几种界面传值
首先在处理iOS-UI中,也许在很多地方需要用到两种甚至多种不同界面之间的传值,相比这也是很多iOS入门成员头疼问题,同样作为新手的我在接触这类传值时候也一脸懵然,经过一段时间的研究,对于简单的传值有 ...
- iOS开发 — (UINaVigationController)导航控制器,界面传值
UINavigationController 继承于 UIViewController , 以栈的方式管理所 控制的视图控制器 . 至少要有一个被管理的视图控制器 ,这个控制器我们称作导航控制器的根视 ...
- JavaScript界面传值与前后台互调
话说曾在校时,前端的第一门课程HTML静态网页设计,其老师,真是应了他的名字: 路遥知马力. 整个学期硬是全部在 Dreamwear 中进行拖拽控件来教学,未曾教授一句代码.成功忽悠了全体学生,课上一 ...
- 如何让iOS 保持界面流畅?这些技巧你知道吗
如何让iOS 保持界面流畅?这些技巧你知道吗 作者:ibireme这篇文章会非常详细的分析 iOS 界面构建中的各种性能问题以及对应的解决思路,同时给出一个开源的微博列表实现,通过实际的代码展示如 ...
- fir.im Weekly - iOS 保持界面流畅的技巧
生命不息,coding 不止.本期 fir.im Weekly 收集了微博上的热转资源,包含 Android.iOS 开发工具.源码分享,产品 UI 设计的好文章,还有一些程序员成长的 Tips,希望 ...
- 属性传值,协议传值,block传值,单例传值四种界面传值方式
一.属性传值 对于属性传值而言,相对于其它的三种 方法来说,是最基础,最简单的一种 方法,但,属性传值 有很大的局限性,因为是适用于第一个界面向第二个界面传 值,第二个向第三个界面传值等等.N界面向N ...
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
iOS页面间传值实现方法:1.通过设置属性,实现页面间传值:2.委托delegate方式:3.通知notification方式:4.block方式:5.UserDefault或者文件方式:6.单例模式 ...
- iOS 8 界面设计 PSD 模板(iPhone 6),免费下载
在 iOS 8 发布不久,Teehan & Lax 就发布了 iOS 8(iPhone6)用户界面的 PSD 模板.该网站分享众多 PSD 模板素材,这些精美的 PSD 界面模板在制作界面原型 ...
随机推荐
- 大数据学习——SparkStreaming整合Kafka完成网站点击流实时统计
1.安装并配置zk 2.安装并配置Kafka 3.启动zk 4.启动Kafka 5.创建topic [root@mini3 kafka]# bin/kafka-console-producer. -- ...
- How to install redis server on CentOS 7 / RHEL 7
在本教程中,我们将学习如何在CentOS 7 / RHEL 7上安装Redis服务器. redis的缩写是REmote DIctionary Server. 它是最流行的开源,高级键值缓存和存储之一. ...
- Django模板导入和替换、以及对数据库的增加、查看
静态文件引入的3中方式:例如对html模板里面对css样式的引入 STATIC_URL = '/static666/'STATICFILES_DIR=[ os.path.join(BASE_DIR,' ...
- 九度oj 1004
题目1004:Median 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:17536 解决:4860 题目描述: Given an incre ...
- struts拦截器详解
拦截器是Struts2最强大的特性之一,它是一种可以让用户在Action执行之前和Result执行之后进行一些功能处理的机制. 说到拦截器interceptor,就会想到过滤器filter: 过滤器f ...
- 使用runtime关联对象将视图添加到视图的类目里
//get方法 - (RJCircularLoaderView*)rj_circularLoaderView { RJCircularLoaderView *loaderView = objc_get ...
- Welcome-to-Swift-08枚举 (Enumerations)
枚举为一系相关联的值定义了一个公共的组类型.同时能够让你在编程的时候在类型安全的情况下去使用这些值. 如果你对C语言很熟悉,你肯定知道在C语言中枚举类型就是一系列具有被指定有关联名称的的整数值.但在S ...
- kb-07线段树--11--区间多重该值多种查询
/* lazy思想的运用,因为查询多种,如果全记录就太繁了,lazy就是如果该区间的每一个叶子的状态都相同就不用深入下去该值,只要暂时标记下,查询的时候也不用下去,直接计算: */ #include& ...
- [SDOI2010] 地精部落 (组合数学,动态规划)
题目链接 Solution 很巧妙的 DP. 可以看这里的题解. 比我自己讲要好的多. Code #include <bits/stdc++.h> using namespace std; ...
- 面试题之redis单线程为什么性能很高
原因是,使用了多路复用技术. 什么是多路复用技术:多个客户端使用一个信道,并且通过一个信道进行传输