表视图学习笔记
来源:互联网 发布:笔记本温度测试软件 编辑:程序博客网 时间:2024/05/16 09:54
// MainViewController.m
// UI_TableView界面传值
//
// Created by dllo on 15/8/7.
// Copyright (c) 2015年 cml. All rights reserved.
//
#import "MainViewController.h"
#import "SecondViewController.h"
// 4.签订协议
@interface MainViewController ()<UITableViewDataSource,UITableViewDelegate,SecondViewController>
@property(nonatomic,retain)NSMutableArray *arr;
@property(nonatomic,retain)UITableView *tableView;
@property(nonatomic ,retain)UIImageView *imageView;
@end
@implementation MainViewController
-(void)dealloc{
[_arrrelease];
[_tableView release];
[superdealloc];
}
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
[superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.arr=[NSMutableArrayarrayWithObjects:@"宋江",@"卢俊义",@"吴用",@"公孙胜",@"关胜",@"林冲",@"秦明" ,@"呼延灼" ,@"花荣",@"柴进",@"李应",@"朱仝",@"鲁智深",@"武松",nil];
}
return self;
}
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
self.navigationController.navigationBar.translucent =NO;
self.tableView =[[UITableViewalloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height-64)style:UITableViewStylePlain];
self.tableView.backgroundColor =[UIColorredColor];
[self.viewaddSubview:self.tableView];
[self.tableViewrelease];
self.tableView.rowHeight =100;
self.tableView.delegate =self;
self.tableView.dataSource=self;
self.imageView =[[UIImageViewalloc] initWithImage:[UIImageimageNamed:[NSStringstringWithFormat:@"1.jpg"]]];
self.imageView.frame =CGRectMake(0, -260,375, 260);
// [self.view addSubview:self.imageView];
[self.imageViewrelease];
// 给tableView添加头视图
// 宽是tableView的宽度
// self.tableView.tableHeaderView =self.imageView;
[self.tableViewaddSubview:self.imageView];
self.tableView.contentInset =UIEdgeInsetsMake(260,0, 0, 0);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *reuse =@"reuse";
UITableViewCell *cell =[tableViewdequeueReusableCellWithIdentifier:reuse];
if (!cell) {
cell =[[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleValue1reuseIdentifier:reuse] autorelease];
}
cell.textLabel.text =self.arr[indexPath.row];
cell.detailTextLabel.text =[NSStringstringWithFormat:@"%ld", indexPath.section];
cell.imageView.image =[UIImageimageNamed:@"1.jpg"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
SecondViewController *secVC=[[SecondViewControlleralloc] init];
secVC.name =self.arr[indexPath.row];
[self.navigationControllerpushViewController:secVC animated:YES];
[secVCrelease];
// 5.设置代理人
secVC.delegate =self;
}
// 6.实现方法
-(void)change:(NSString *)value{
//属性的数组,相当于数据源,把传过来的织田见到数组中
if(![value isEqualToString:@""]){
[self.arraddObject:value];
//对tableView进行刷新操作
[self.tableViewreloadData];
}
}
#pragma mark tableView 的delegate已经签订好scrollView的协议,只要设置代理人,就可以使用scrollView的协议方法
// 只要滑动就会触发
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
NSLog(@"滑动");
// 获取偏移量
CGFloat y =scrollView.contentOffset.y;
NSLog(@"%g",y);
if (y<-260) {
self.imageView.frame =CGRectMake(0, y,self.view.frame.size.width, -y);
}
}
// SecondViewController.h
// UI_TableView界面传值
//
// Created by dllo on 15/8/7.
// Copyright (c) 2015年 cml. All rights reserved.
//
#import <UIKit/UIKit.h>
// 声明一份协议
@protocol SecondViewController <NSObject>
-(void)change:(NSString *)value;
@end
@interface SecondViewController :UIViewController
@property(nonatomic,copy)NSString *name;
// 设置代理人属性
@property(nonatomic ,assign)id<SecondViewController>delegate;
@end
// SecondViewController.m
// UI_TableView界面传值
//
// Created by dllo on 15/8/7.
// Copyright (c) 2015年 cml. All rights reserved.
//
#import "SecondViewController.h"
@interface SecondViewController ()<UITextFieldDelegate>
@property(nonatomic,retain)UILabel *label;
@property(nonatomic,retain)UITextField *textField;
@property(nonatomic ,retain)UIButton *button;
@end
@implementation SecondViewController
-(void)dealloc{
[_labelrelease];
[_textField release];
[_buttonrelease];
[_namerelease];
[superdealloc];
}
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor =[UIColoryellowColor];
// 建一个 label
self.label =[[UILabelalloc] initWithFrame:CGRectMake(100,100, 100, 30)];
self.label.backgroundColor =[UIColorredColor];
self.label.layer.borderWidth =1;
self.label.layer.cornerRadius =5;
self.label.layer.masksToBounds=YES;
// 对label进行赋值
self.label.text =self.name;
[self.viewaddSubview:self.label];
[self.labelrelease];
// 建一个 textField
self.textField =[[UITextFieldalloc] initWithFrame:CGRectMake(100,200, 100, 30)];
self.textField.layer.borderWidth =1;
self.textField.layer.cornerRadius =5;
self.textField.backgroundColor =[UIColorcyanColor];
[self.viewaddSubview:self.textField];
[self.textFieldrelease];
// 建一个 button
self.button =[UIButtonbuttonWithType:UIButtonTypeSystem];
self.button.frame=CGRectMake(100,300, 100, 30);
[self.viewaddSubview:self.button];
self.button.layer.borderWidth=1;
self.button.layer.cornerRadius=5;
[self.buttonsetTitle:@"返回"forState:UIControlStateNormal];
self.button.backgroundColor =[UIColorredColor];
[self.buttonaddTarget:selfaction:@selector(click:)forControlEvents:UIControlEventTouchUpInside];
self.textField.delegate =self;
}
-(void)click:(UIButton *)button{
[self.navigationControllerpopToRootViewControllerAnimated:YES];
[self.delegatechange:self.textField.text];
}
#pragma mark 点击return 回收键盘
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[self.textFieldendEditing:YES];
return YES;
}
- 表视图学习笔记
- [学习笔记]web视图
- iOS学习笔记-003.视图 & 视图控制器
- AppFuse学习笔记-视图层
- 物化视图学习笔记一
- oracle物化视图学习笔记
- MySQL学习笔记14:视图
- 导航视图控制器-------------学习笔记
- openGL学习笔记之一--视图
- 导航视图控制器学习笔记
- Scala学习笔记--视图界定
- MySQL学习笔记14:视图
- Mysql学习笔记六,视图
- 《MySQL必知必会学习笔记》:视图
- MySQL学习笔记—视图
- Thinkphp5 学习笔记之视图
- APS.NET_MVC5学习笔记-视图
- iOS集合视图学习笔记
- 杭电 1686 Oulipo (kmp)
- 北大POJ_1050_To the Max
- HDOJ 1253 胜利大逃亡 (三维BFS+技巧)
- 大型网站软件系统的简单说一下
- 12、C语言和设计模式(代理模式)
- 表视图学习笔记
- 线程栈模型与线程的变量、线程状态转换
- log4net按日志级别(debug,info,warn,error,fatal)生成日志目录,同时每小时生成一个日志文件
- Android学习心得(11) --- MAC下Android反编译(3)
- BZOJ 2049 [Sdoi2008]Cave 洞穴勘测 LCT
- Can not find the tag library descriptor for "/struts-tags"
- Why Docker is Not Yet Succeeding Widely in Production
- java Socket多线程聊天程序(适合初学者)
- poj 2406 Power Strings (kmp)