IOS 学习九 Navigation Controller 的使用示例
2015-04-30 16:42
190 查看
1.新建Single View Application项目命名为RecipeBook
2.选中当前的ViewController,点击菜单Editor-Embed in-Navigation Controller, 这样把当前ViewController转为Navigation Controller
3.在第二个ViewController里,放一个TableView,修改ViewController.h:
4.选择ViewController.m,定义一个可变数组:
这里直接把后面代码都贴上了:
5.选中Table View,右键拖动到ViewController
弹出的菜单里有dataSource delegate,操作两次都选择上。
6.设置Title
7.添加ViewController,放一个label
设置TableView
把TableView和新的ViewController建立关联
在TableView上点右键拖到新的viewcontroller上,选择Show
运行测试。
2.选中当前的ViewController,点击菜单Editor-Embed in-Navigation Controller, 这样把当前ViewController转为Navigation Controller
3.在第二个ViewController里,放一个TableView,修改ViewController.h:
#import <UIKit/UIKit.h> @interface ViewController : UIViewController <UITableViewDelegate,UITableViewDataSource> @end
4.选择ViewController.m,定义一个可变数组:
这里直接把后面代码都贴上了:
#import "ViewController.h" @interface ViewController () { NSArray *recipes; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. recipes=[NSArray arrayWithObjects:@"Egg",@"mushroom",@"Full bread",nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [recipes count]; } -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIndentifier = @"RecipeCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIndentifier]; if(cell==nil){ cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIndentifier]; } cell.textLabel.text=[recipes objectAtIndex:indexPath.row]; return cell; } @end
5.选中Table View,右键拖动到ViewController
弹出的菜单里有dataSource delegate,操作两次都选择上。
6.设置Title
7.添加ViewController,放一个label
设置TableView
把TableView和新的ViewController建立关联
在TableView上点右键拖到新的viewcontroller上,选择Show
运行测试。
相关文章推荐
- ***iOS学习之Table View的简单使用和DEMO示例(共Plain普通+Grouped分组两种)
- IOS基础学习日志(七)利用dispatch_once创建单例及使用
- iOS学习笔记2-使用Audio Queues录音,取得实时PCM数据
- iOS学习笔记4-GCDAsyncUdpSocket的使用(实现异步发送接收数据)
- iOS学习笔记6- iOS UICollectionView简单使用
- iOS学习笔记9- iOS 如何使用TestFlight进行Beta测试
- 【iOS学习笔记】CocoaPods使用详细说明
- iOS学习(其他小控件的使用)
- IOS学习之一个示例弄懂代理(delegate)和协议
- iOS学习笔记:UISearchBar使用
- iOS学习之NSBundle介绍和使用
- iOS 9学习系列:如何使用ATS提高应用的安全性
- iOS 9学习系列:如何使用ATS提高应用的安全性
- iOS 9学习系列:如何使用ATS提高应用的安全性
- UI初级第七课  表视图的使用——iOS学习连载22
- [iOS]学习数据库操作(使用FMDB)
- iOS学习笔记20-通过AirServer使用AirPlay镜像并实现多屏幕显示控制
- iOS学习第八篇 ——NSString的使用
- iOS深入学习(使用CocoaPods进行第三方资源管理)
- iOS学习之CoreData多表关联使用