功能:点击列表项,用列表字符串作为参数创建一个新视图,新视图默认可以有一个BACK按钮回到上一个视图

//
// main.m
// Hello
//
// Created by lishujun on 14-8-28.
// Copyright (c) 2014年 lishujun. All rights reserved.
// #import <UIKit/UIKit.h> // ------------- 接受参数的视图控制器-------------
@interface TestViewController : UIViewController
@end @implementation TestViewController -(TestViewController *)initWithArg:(NSString *)arg
{
NSLog(@"%@", arg);
return self;
} -(void) loadView
{
//创建视图对象
UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor lightGrayColor];
self.view = contentView;
}
@end // --------------视图控制器对象--------------
@interface HelloWorldViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
UITableView *tableView;
NSArray *array;
}
@end @implementation HelloWorldViewController -(HelloWorldViewController *) init
{
array = [[NSArray alloc]initWithObjects:@"oops", @"hello", @"world", nil];
return self;
} -(void) loadView
{
//创建视图对象
UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor lightGrayColor];
self.view = contentView; tableView = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[self.view addSubview:tableView];
tableView.dataSource = self;
tableView.delegate = self;
} // --------DataSource接口必须实现的方法,用于填充表格-----------
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return ; //设定列表分区个数
} -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array count]; //设定列表长度
} -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 生成列表单元(尽可能复用已有单元)
static NSString *simpleTableIdentifer = @"SimpleTableIdentifer"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifer];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifer];
}
cell.textLabel.text = array[indexPath.row];
return cell;
} // ----------实现Delegate接口的方法,用于操作---------------
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//行选中事件
NSString *rowValue = array[indexPath.row];
[tableView deselectRowAtIndexPath:indexPath animated:YES]; //取消选中状态
[self.navigationController pushViewController:[[TestViewController alloc]initWithArg:rowValue] animated:YES];
} @end // ----------------委托对象--------------------
@interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate>
{
IBOutlet UIWindow *window;
} @property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UINavigationController *nav; @end @implementation HelloWorldAppDelegate @synthesize window;
@synthesize nav; -(void) applicationDidFinishLaunching:(UIApplication *)application
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
HelloWorldViewController *viewController = [[HelloWorldViewController alloc]init]; self.nav = [[UINavigationController alloc]initWithRootViewController: viewController];
self.window.rootViewController = self.nav;
[self.window makeKeyAndVisible];
}
@end // ---------------程序入口---------------------
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate");
}
}

iOS:NAV+TABLE结合的更多相关文章

  1. [转][iOS]NSHash​Table & NSMap​Table

    NSSet and NSDictionary, along with NSArray are the workhorse collection classes of Foundation. Unlik ...

  2. iOS nav加角标

    写一个类别加上就可以啦 #import "UIBarButtonItem+Badge.h" #import "BadgeView.h" #import < ...

  3. Table View Programming Guide for iOS---(一)---About Table Views in iOS Apps

    About Table Views in iOS Apps Table views are versatile user interface objects frequently found in i ...

  4. 史上最全的常用iOS的第三方框架

    文章来源:http://blog.csdn.net/sky_2016/article/details/45502921 图像: 1.图片浏览控件MWPhotoBrowser       实现了一个照片 ...

  5. 常用iOS的第三方框架

    图像:1.图片浏览控件MWPhotoBrowser       实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等 ...

  6. iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)--(转)

    图像: 1.图片浏览控件MWPhotoBrowser 实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等操作. 下 ...

  7. iOS开发--开源库

    图像: 1.图片浏览控件MWPhotoBrowser        实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩 ...

  8. iOS - 常用iOS的第三方框架

    图像:1.图片浏览控件MWPhotoBrowser       实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等 ...

  9. iOS-----GitHub上比较齐全的iOS 工具和App

    Github-iOS 工具 和 App   系统基础库 Category/Util sstoolkit 一套Category类型的库,附带很多自定义控件 功能不错-       BFKit 又一套Ca ...

随机推荐

  1. 基于前端javascript的搜索功能

    发表于 2013/11/07 当在数据量不是很大,而且没有后端对应的功能接口的时候,一些简单的搜索功能基本上是前端去实现的,正好最近用到,写了一个,贴出来和大家分享: 功能描述: 按下键盘后及时搜索条 ...

  2. Memcached笔记——(四)应对高并发攻击【转】

    http://snowolf.iteye.com/blog/1677495 近半个月过得很痛苦,主要是产品上线后,引来无数机器用户恶意攻击,不停的刷新产品各个服务入口,制造垃圾数据,消耗资源.他们的最 ...

  3. 使用Parse内付费服务出现的Error Domain=Parse Code=146 "The operation couldn’t be completed. (Parse error 146.)

    因为开发一个应用有个内付费去广告功能,介于苹果官方提供的方法没用过,感觉有些复杂,于是选用了第三方组件Parse来解决这个问题,简单易操作: Parse简化苹果官方内付费问题,使用方法分厂简单只有两个 ...

  4. Hadoop-2.4.1学习之Map任务源代码分析(下)

    在Map任务源码分析(上)中,对MAP阶段的代码进行了学习,这篇文章文章将学习Map任务的SORT阶段.假设Reducer的数量不为0.则还须要进行SORT阶段.但从上面的学习中并未发现与MAP阶段运 ...

  5. cookie记录用户名和密码

    getAttribute和getParameter的区别: request.getAttribute():是request时设置的变量的值,用request.setAttribute("na ...

  6. static inner class 什么时候被加载

    一直认为在加载outer class 的同时也会加载inner class 并且完成静态变量和代码块的初始化,今天在维基百科上面看到 “The static class definitionLazyH ...

  7. WTL的核心机制

    WTL背景介绍 WTL是微软ATL开发组成员Nenad Stefanovic先生在ATL Windowing机制上发展起来的一整套GUI框架,运用template技术组织和创建GUI对象,构筑了精致的 ...

  8. Pagekit安装

    Pagekit 是一个模块化,轻量的 CMS 系统,基于现代化的技术,如 Symfony 组件和 Doctrine.它提供了一个很好的平台,用于主题和延伸开发.Pagekit 为您提供了工具来创造美丽 ...

  9. MYSQL批处理

    待更新 版权声明:本文为博主原创文章,未经博主允许不得转载.

  10. css3新增加的选择器

    css3新增加的选择器 一.属性选择器: E[attr] 只要有属性名E[attr=value] 属性名=属性值E[attr~=blue] 包含这个blue整个单词就可以E[attr^=c] 以这个字 ...