今天有些匆忙。

效果图如下:

代码如下:

#import <UIKit/UIKit.h>
#import "FirstViewController.h" @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
FirstViewController *first=[[FirstViewController alloc]init];
UINavigationController *navc=[[UINavigationController alloc]initWithRootViewController:first];
self.window.rootViewController=navc;
return YES;
}
#import <UIKit/UIKit.h>
#import "SecondViewController.h" @interface FirstViewController : UIViewController<UITableViewDataSource,UITableViewDelegate,postValueDelegate> @property(strong,nonatomic)UITableView * tableview; @property(strong,nonatomic)NSMutableArray *array; @property(strong,nonatomic)NSString *st; @end
#import "FirstViewController.h"

@interface FirstViewController ()

@property(assign,nonatomic)int a;

@end

@implementation FirstViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor yellowColor];
self.title=@"首页";
UIBarButtonItem *nextItem=[[UIBarButtonItem alloc]initWithTitle:@"下一页" style:UIBarButtonItemStylePlain target:self action:@selector(nextpage)];
self.navigationItem.rightBarButtonItem=nextItem; self.array=[NSMutableArray array]; for (int i=1; i<20; i++) {
[self.array addObject:[NSString stringWithFormat:@"你摔了%d跤",i]];
} self.tableview=[[UITableView alloc]initWithFrame:self.view.frame style:1]; self.tableview.separatorColor=[UIColor redColor]; self.tableview.delegate=self; self.tableview.dataSource=self; [self.view addSubview:self.tableview]; [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
} -(void)postvalue:(NSString *)str
{
// self.st=str; [self.array replaceObjectAtIndex:self.a withObject:str]; [self.tableview reloadData]; // NSLog(@"%@",self.st); } #pragma mark 数据源 每个分区显示行数设置
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.array.count;
} #pragma mark 数据源 每个单元格显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//单元格重用机制
static NSString * cellIdentity=@"cell"; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentity forIndexPath:indexPath];
cell.textLabel.text=self.array[indexPath.row]; return cell;
} -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ NSLog(@"%@",self.array[indexPath.row]); self.st=self.array[indexPath.row];
SecondViewController *second=[[SecondViewController alloc]init];
second.str=self.st;
second.delegate=self;
self.a=(int)indexPath.row; NSLog(@"%d",self.a); [self.navigationController pushViewController:second animated:YES];
} -(void)nextpage
{
SecondViewController *second=[[SecondViewController alloc]init]; second.str=self.st; [self.navigationController pushViewController:second animated: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
#import <UIKit/UIKit.h>
//创建协议,声明方法
@protocol postValueDelegate <NSObject> -(void)postvalue:(NSString* )str; @end @interface SecondViewController : UIViewController<UITextFieldDelegate> @property(strong,nonatomic) UITextField * textName; @property(strong,nonatomic) NSString *str; @property(strong,nonatomic) id<postValueDelegate> delegate; @end
#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor greenColor];
self.navigationItem.hidesBackButton=YES;
self.title=@"尾页";
self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"back" style:2 target:self action:@selector(backpage)]; self.textName=[[UITextField alloc]initWithFrame:CGRectMake(100, 300, 150, 60)]; self.textName.borderStyle=1; self.textName.text=self.str; self.textName.delegate=self; [self.view addSubview:self.textName];
} -(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ([textField isFirstResponder]) {
[textField resignFirstResponder];
} if (self.delegate) {
[self.delegate postvalue:self.textName.text]; } [self.navigationController popToRootViewControllerAnimated:YES]; return YES;
} -(void)backpage
{
if (self.delegate) {
[self.delegate postvalue:self.textName.text];
NSLog(@"%@",self.textName.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

最新文章

  1. 云计算之路-阿里云上:“黑色1秒”最新线索——w3tp与w3dt
  2. loadRunner录制脚本常见问题及解决方法
  3. SQL SERVER 2008中输入汉字乱码的问题
  4. Activiti系列: 如何添加自定义表单引擎
  5. 【积硅计划】html标签
  6. 网络流(最大流) CodeForces 546E:Soldier and Traveling
  7. dp优化
  8. 浅谈API设计
  9. android Spinner 续
  10. aps.net验证控件的异常处理
  11. Selenium Grid2
  12. Settings.settings
  13. HTML编码和CSS编码会遇到的问
  14. 使用Js进行linq处理
  15. Hello jna
  16. 用keytool制作证书并在tomcat配置https服务(一)
  17. 第一册:lesson sixty one.
  18. 操作过程-CentOS7下添加新硬盘扩充已经存在的逻辑卷分区的存储空间
  19. 解决zabbix可用性为灰色状态
  20. 交互题(二分)(D. Game with modulo)

热门文章

  1. SQL--分页查询
  2. Git undo 操作
  3. JavaScript基础—dom,事件
  4. 【转载】关于BooleanQuery在搜索中的用处
  5. ios开发入门资料整理
  6. WinForm 简单蒙版实现控件遮盖
  7. 点击显示div
  8. 算法:求幂(python版)
  9. MUI(5)
  10. ThinkCMF-首页Nav部分菜单配置详解