功能:点击列表项,用列表字符串作为参数创建一个新视图,新视图默认可以有一个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. 利用Linq对集合元素合并、去重复处理

    本文转载:http://www.cnblogs.com/yjmyzz/archive/2012/12/18/2823170.html 今天写代码时,需要对一个数组对象中按一定规则合并.去重处理,不想再 ...

  2. MVC 音乐商店 第 9 部分: 注册和结帐

    MVC 音乐商店是介绍,并分步说明了如何使用 ASP.NET MVC 和 Visual Studio 为 web 开发教程应用程序. MVC 音乐商店是一个轻量级的示例存储实现它卖音乐专辑在线,并实现 ...

  3. DragQueryFile

    附件:http://files.cnblogs.com/xe2011/CSharp_DragQueryFile.rar using System.Runtime.InteropServices; th ...

  4. json xmpp

    https://github.com/lamfire/jspp http://blog.csdn.net/nomousewch/article/category/823687 http://my.os ...

  5. Ⅲ.AngularJS的点点滴滴-- 路由

    路由ngRoute (需要依赖ngRoute模块) <html> <script src="http://ajax.googleapis.com/ajax/libs/ang ...

  6. centos6.6 install

    文中下载链接以中断 请另行下载 #!/bin/bash rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8. ...

  7. Command Line-Version (SetACL.exe) – Syntax and Description

    For a quick start, tell SetACL the following: Object name (-on): This is the path to the object SetA ...

  8. SELECT [Code] ,[AlarmID] ,[ItemName] ,[isDeleted] ,[Remark] FROM [LjlData].[dbo].[T_BaseDetail] union select 0--

    SELECT  [id]       ,[AlarmID]       ,[ItemName]       ,[isDeleted]       ,[Remark]   FROM [LjlData]. ...

  9. bootstrap3.0 模态框显示的文字超出怎么办

    版本:bootstrap3.3 模态框文字超出 解决方案: 在html中控制自动换行   其实只要在表格控制中添加一句<div style="word-break:break-all& ...

  10. iOS 开发工具

    Github 社区 https://github.com/ iOS 开发类库 http://www.code4app.com/thread-7831-1-1.html (出处: Code4App-iO ...