您的位置:首页 > 产品设计 > UI/UE

浅谈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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: