浅谈UITableview 基本使用
2015-09-25 09:51
471 查看
UItableview分两种样式Plain,Group
UItableviewCell
自定义:首先先建立一个继承与uitableviewcell的view 然后我们进入xib
将view删除 从右边的工具箱 托一个uitableviewcell 进来 然后我们让这个cell继承与刚才建立的那个view
做完这一步 你的自定义cell 就做完了 追后你就可以在你刚才拖放进来的cell上面 任意拖放控件
下面我们就来讲一下 如何在你的controller中使用table
Test.h文件
@interface Test : UIViewController
<
UITableViewDelegate,
UITableViewDataSource
>
{
IBOutlet
UITableview *table;//定义table
并且和xib上面的table进行关联 就是用线托一下
}
@end
@implementation DetailListViewController
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return
10;//返回在当前section中有多少个cell
}
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString* identifier = @"identifier"; //id 和自定义cell的id绑定
自定义cell名字*
cell = (自定义cell名字*)[tableView
dequeueReusableCellWithIdentifier:identifier];
if (cell ==
nil) {
//cell =
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:identifier];
NSArray*
nibs = [[NSBundle mainBundle] loadNibNamed:@"自定义cell名字" owner:self
options:nil];
for (id
oneObject in nibs)
{
if
([oneObject isKindOfClass:[自定义cell名字 class]])
{
cell =
(自定义cell名字*)oneObject;
}
}
}
return cell;
}
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//点击cell时候触发
}
- (CGFloat)tableView:(UITableView *)tableView
heightForFooterInSection:(NSInteger)section
{
//根据section 返回每一行的高度
}
@end
大致使用就是 这个样子 如果有哪里不明白 可以直接联系我 我的sina微薄是 杨教授v
UItableviewCell
自定义:首先先建立一个继承与uitableviewcell的view 然后我们进入xib
将view删除 从右边的工具箱 托一个uitableviewcell 进来 然后我们让这个cell继承与刚才建立的那个view
做完这一步 你的自定义cell 就做完了 追后你就可以在你刚才拖放进来的cell上面 任意拖放控件
下面我们就来讲一下 如何在你的controller中使用table
Test.h文件
@interface Test : UIViewController
<
UITableViewDelegate,
UITableViewDataSource
>
{
IBOutlet
UITableview *table;//定义table
并且和xib上面的table进行关联 就是用线托一下
}
@end
@implementation DetailListViewController
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return
10;//返回在当前section中有多少个cell
}
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString* identifier = @"identifier"; //id 和自定义cell的id绑定
自定义cell名字*
cell = (自定义cell名字*)[tableView
dequeueReusableCellWithIdentifier:identifier];
if (cell ==
nil) {
//cell =
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:identifier];
NSArray*
nibs = [[NSBundle mainBundle] loadNibNamed:@"自定义cell名字" owner:self
options:nil];
for (id
oneObject in nibs)
{
if
([oneObject isKindOfClass:[自定义cell名字 class]])
{
cell =
(自定义cell名字*)oneObject;
}
}
}
return cell;
}
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//点击cell时候触发
}
- (CGFloat)tableView:(UITableView *)tableView
heightForFooterInSection:(NSInteger)section
{
//根据section 返回每一行的高度
}
@end
大致使用就是 这个样子 如果有哪里不明白 可以直接联系我 我的sina微薄是 杨教授v
相关文章推荐
- UIView适应内容
- BFS HDOJ 1242 Rescue
- UIView内容的伸缩区域
- uva 11324 The Largest Clique(图论-tarjan,动态规划)
- UI:SQL语句
- UI:简单的SQL语句
- IOS UIImagePickerViewController相关(转)
- Xcode7 UI自动化测试详解 带demo UITests
- Winform- 界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用
- easyui 如何使个别onExpandRow的+号隐藏
- TouchAndGuest触摸事件和手势
- Learning Bluemix 有新 Logo 了
- *LeetCode-Unique Binary Search Trees II
- Easyui Datagrid rownumbers行号四位、五位显示不完全的解决办法
- iOS开发——高级篇——UIDynamic 物理引擎
- 接口测试工具Soapui5.1.2参数化之Properties20150924
- 破坏神(1)NGUI实现首个界面
- easyui升级到1.43之后,编辑行的高度就固定了 (变矮了)
- easyui分类显示默认折叠
- UVA1423Guess (dfs,bfs拓扑排序)