IOS Xcode5 IB tableView 简单使用
2014-07-10 16:44
513 查看
在Xcode5上使用IB界面做tableView的简单的使用。
1,在IB上加入一个table view。2,右键table view,将这个table view的Delegate和dataSource分别与file ownsr关联起来,要关联两次。3,在这个IB对应的controller的头文件中添加协议<UITableViewDataSource,UITableViewDelegate>,并且定义一个列表作为属性,@property(nonatomic,strong)NSArray
* list;4,在controller源文件中,先要@synthesize之前定义的list,然后在viewDidLoad中初始化要显示的内容,举个简单例子:NSArray
* array = [[NSArray
alloc]initWithObjects:@"简体中文",@"English",@"日本語",nil
]; self.list
= array;我们遵守的协议中有三个方法是必须实现的,实现可以参考以下:
-(int)tableView:(UITableView*)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.list
count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static NSString * TableIdentifier =
@"TableIdentifier";
UITableViewCell * cell
= [tableView
dequeueReusableCellWithIdentifier:TableIdentifier];
if(nil == cell)
{
cell = [[UITableViewCell
alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:TableIdentifier];
}
NSUInteger row = [indexPath
row];
cell.textLabel.text = [self.list
objectAtIndex:row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath
{
NSString *rowString = [self.list
objectAtIndex:[indexPath
row]];
UIAlertView * alter = [[UIAlertView
alloc] initWithTitle:@"您选择的语言:" message:rowString
delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil,
nil];
[alter
show];
}
运行一下就行了。
1,在IB上加入一个table view。2,右键table view,将这个table view的Delegate和dataSource分别与file ownsr关联起来,要关联两次。3,在这个IB对应的controller的头文件中添加协议<UITableViewDataSource,UITableViewDelegate>,并且定义一个列表作为属性,@property(nonatomic,strong)NSArray
* list;4,在controller源文件中,先要@synthesize之前定义的list,然后在viewDidLoad中初始化要显示的内容,举个简单例子:NSArray
* array = [[NSArray
alloc]initWithObjects:@"简体中文",@"English",@"日本語",nil
]; self.list
= array;我们遵守的协议中有三个方法是必须实现的,实现可以参考以下:
-(int)tableView:(UITableView*)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.list
count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static NSString * TableIdentifier =
@"TableIdentifier";
UITableViewCell * cell
= [tableView
dequeueReusableCellWithIdentifier:TableIdentifier];
if(nil == cell)
{
cell = [[UITableViewCell
alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:TableIdentifier];
}
NSUInteger row = [indexPath
row];
cell.textLabel.text = [self.list
objectAtIndex:row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath
{
NSString *rowString = [self.list
objectAtIndex:[indexPath
row]];
UIAlertView * alter = [[UIAlertView
alloc] initWithTitle:@"您选择的语言:" message:rowString
delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil,
nil];
[alter
show];
}
运行一下就行了。
相关文章推荐
- iOS学习之Table View的简单使用
- iOS学习之Table View的简单使用
- iOS学习之Table View的简单使用
- iOS开发系列----UI(简单TableView的使用)
- Qt TableView的简单使用
- iOS学习之Table View的简单使用
- iOS--TableView的简单使用
- ios开发中最简单的tableview使用一
- 简单tableView的使用
- iOS学习之Table View的简单使用
- iOS学习之Table View的简单使用
- Qt TableView的简单使用
- ios开发入门- tableview 简单使用(一)
- iOS学习之Table View的简单使用
- Qt TableView的简单使用
- iOS学习之Table View的简单使用
- Qt TableView的简单使用
- tableView 简单使用
- iOS学习之Table View的简单使用
- ***iOS学习之Table View的简单使用和DEMO示例(共Plain普通+Grouped分组两种)