代码创建TableView 代码例子
来源:互联网 发布:ppt哪个软件 编辑:程序博客网 时间:2024/06/06 18:31
#import "TableViewController2.h"
@interface TableViewController2 ()
@end
@implementation TableViewController2
@synthesize mytableview;
@synthesize dataList;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *list = [NSArray arrayWithObjects:@"武汉",@"上海",@"北京",@"深圳",@"广州",@"重庆",@"香港",@"台海",@"天津", nil];
self.dataList = list;
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain] ;
// 设置tableView的数据源
tableView.dataSource = self;
// 设置tableView的委托
tableView.delegate = self;
// 设置tableView的背景图
// tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Background.png"]];
self.mytableview=tableView;
self.mytableview = tableView;
[self.view addSubview:mytableview];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections. //这几个你就看英文吧
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [dataList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellWithIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellWithIdentifier];//这里123来设置不同的风格
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [self.dataList objectAtIndex:row];
//cell.imageView.image = [UIImage imageNamed:@"green.png"];
cell.detailTextLabel.text = @"详细信息";
return cell;
}
@interface TableViewController2 ()
@end
@implementation TableViewController2
@synthesize mytableview;
@synthesize dataList;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *list = [NSArray arrayWithObjects:@"武汉",@"上海",@"北京",@"深圳",@"广州",@"重庆",@"香港",@"台海",@"天津", nil];
self.dataList = list;
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain] ;
// 设置tableView的数据源
tableView.dataSource = self;
// 设置tableView的委托
tableView.delegate = self;
// 设置tableView的背景图
// tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Background.png"]];
self.mytableview=tableView;
self.mytableview = tableView;
[self.view addSubview:mytableview];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections. //这几个你就看英文吧
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [dataList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellWithIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellWithIdentifier];//这里123来设置不同的风格
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [self.dataList objectAtIndex:row];
//cell.imageView.image = [UIImage imageNamed:@"green.png"];
cell.detailTextLabel.text = @"详细信息";
return cell;
}
0 0
- 代码创建TableView 代码例子
- mac 纯代码创建tableview
- iOS 代码如何创建静态tableView
- swift 里面tableview的cell代码创建方法
- tableview(傻帽代码)
- 纯代码TableView实例
- UIKit-TableView--TableView用代码自定义cell
- IOS 整理tableview的代码
- 【纯代码】TableView简单配置
- tableview----Grouped(纯代码)
- Design Pattern 创建型模式章节例子的代码
- 60-给自定义的tableView的cell创建分割线(代码封装)
- 经典Robocode例子代码
- ASP经典代码例子
- Prim 算法代码例子
- Windows socket 代码例子
- TEF例子代码
- 委托例子代码
- 图论相关(更新5.31)
- 一个整数数列,元素取值可能是1~N(N是一个较大的正整数)中的任意一个数,相同数值不会重复出现。设计一个算法,找出数列中符合条件的数对的个数,满足数对中两数的和等于N+1
- 面试题:砝码问题
- Android 模拟器中安装软件程序如QQ
- 利用jdk自带的强悍工具jvisualvm检测多线程的竞争
- 代码创建TableView 代码例子
- POJ 3579- Median
- BST树的实现
- 哈希函数有关知识
- dede:likearticle 调用自定义字段
- JVM学习笔记4(安全管理器)
- 【BZOJ】【P1899】【ZJOI2004】【Lunch 午餐】【题解】【DP】
- 我不想说再见
- gabor function