//应用程序代理
@interface SimpleTableViewAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window; //程序主窗体
UINavigationController *navigationController; //在接口中定义导航控制器
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UINavigationController *navigationController;
@end
//引入接口
#import "SimpleTableViewAppDelegate.h"
#import "RootViewController.h" //继承UITableViewController的子类接口
@implementation SimpleTableViewAppDelegate
@synthesize window;
@synthesize navigationController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
/*
通过一般样式初始化UITableViewController子类
*/
RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
//接收一个数组,数据从当前系统获得所有时区作为数组的元素
NSArray *timeZones = [NSTimeZone knownTimeZoneNames];
//根视图控制器UITableViewController中时区名的数组数据等于排序后的时区数组数据
rootViewController.timeZoneNames = [timeZones sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
//------------知识点-------------
//编程实例化一个导航控制器,并没有继承某个类或者遵循某个协议,关键是initWithRootViewController:rootViewController方法,他是把rootViewController实例作为导航控制器的根视图。
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
//赋值到当前程序代理接口中定义的导航控制器类的实体
self.navigationController = aNavigationController;
[aNavigationController release];
[rootViewController release];
//把导航控制器的视图增加到当前的window对象中。
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
- (void)dealloc {
[navigationController release];
[window release];
[super dealloc];
}
@end
//表视图控制器子类
@interface RootViewController : UITableViewController {
NSArray *timeZoneNames; //存储所有时区名字
}
@property (nonatomic, retain) NSArray *timeZoneNames;
@end
#import "RootViewController.h"
#import "SimpleTableViewAppDelegate.h"
@implementation RootViewController
@synthesize timeZoneNames;
- (void)viewDidLoad {
//设定当前控制器的标题,以备导航控制器显示
//通过第一个参数作为键取当前程序沙盒中找Localizable.strings文件中的内容,第二个参数是备注这个字段的意思,不显示到界面中的。
self.title = NSLocalizedString(@"Time Zones", @"Time Zones title");
}
//接口继承自UITableViewController,需要实现这个方法获得一共有多少部分。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// 这里只有一个部分.
return 1;
}
//接口继承自UITableViewController,需要实现这个方法获得每一部分有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of time zone names.
return [timeZoneNames count];
}
//回调方法,表格视图控制器的每一行的显示都是通过这个方法进行处理的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
// Try to retrieve from the table view a now-unused cell with the given identifier.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
// If no cell is available, create a new one using the given identifier.
if (cell == nil) {
// Use the default cell style.
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
// 从时区数组中获得当前行号对应的时区数据作为这行的文本显示
NSString *timeZoneName = [timeZoneNames objectAtIndex:indexPath.row];
cell.textLabel.text = timeZoneName;
return cell;
}
/*
To conform to Human Interface Guildelines, since selecting a row would have no effect (such as navigation), make sure that rows cannot be selected.
当对表格行进行选择时,禁止做选择动作。
*/
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
return nil;
}
- (void)dealloc {
[timeZoneNames release];
[super dealloc];
}
@end
分享到:
相关推荐
导航控制器(UINavigationController)用来管理一系列显示层次型信息的场景。一般而言,逐步显示更详细的信息。 导航控制器 -- 用户在场景之间切换时,导航控制器依次将视图控制器压入(push)堆栈中,且当前场景的...
我们写iOS项目的时候,基本都是一个UINavigationController套一个UITabBarController的形式,就是上面一个导航栏,下面几个按钮的工具条的形式。我写了几个应用,发现如果每次都重新写的话完全就是浪费精力和时间,...
上传的demo关于UINavigationController中back按钮的重写方法, UINavigationController的back按妞本身是没有监听方法的,但是我们通过添加类目可以使back按钮具有监听的作用.让我们能在UINavigationController触发返回...
UInavigationController笔记
UINavigationController 简单使用方法,增加自定义导航按钮。图片按钮,switch按钮。
很多时候我们创建一个基于UITabBarController的application以后还希望能够在每个tab view都可以实现导航控制,即添加一个UINavigationController来实现tabview内部的view之间的切换,这即是本文所要介绍的。
IOS7 UINavigationController滑动Demo,解决了在push后的页面可以滑动返回的问题。
页面跳转 UITabBarController+UINavigationController+UIViewController
iOS UINavigationController自定义,push动画效果
一个小demo,演示如何隐藏tabbar
UINavigationController导航控制器
UITabBarController和UINavigationController的整合使用DEMO,详情见:http://blog.csdn.net/hwe_xc/article/details/50588500
* 从iOS7开始,系统为UINavigationController提供了一个interactivePopGestureRecognizer用于右滑返回(pop),但是,如果自定了返回按钮或者隐藏了navigationBar,该手势就失效了。 ## 原因 * 自定义返回按钮或者隐藏...
相关知识共享: leftBarButtonItem与backBarButtonItem的区别 - http://blog.csdn.net/moon_prince2013/article/details/49079251 ViewController中[self setTtile]与[self.navigationItem setTitle]的... ... ...
iphone中的基础控件UINavigationController,适合初学者,主要学习UINavigationController的基本属性和常用方法调用。 UINavigationController也是一种常用的容器,跟前边学过的tabbar差不多,在这个容器中可以添加...
让 UINavigationController 支持全屏操作手势.zip,A UINavigationController's category to enable fullscreen pop gesture with iOS7 system style.
该文件包括了uinavigationcontroller,介绍了怎么设置其属性,以及相应的管理控制器,实现了其所有的代理方法
iOS 使用UINavigationController 进行页面跳转 http://blog.csdn.net/liuyan20092009/article/details/52233769
自定义UITabBar,layoutSubviews重写UITabBarButton位置,重写则hitTest方法并监听按钮的点击 自定义的UITabBarController和UINavigationController