uitableview 跳转指定区域

 tableviewcontroal 是uiviewcontral 的子类;

//创建几行分区 默认是一

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

NSIndexPath *index;


 index=[NSIndexPath indexPathForRow:b inSection:a];//第a个区域里的第b行。

[table scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionBottom animated:YES];

跳转到第index着行,第二个参数是个枚举的,第三个是动效。 

 有一个小问题, 就是在跳转到最后一个区域de时候总是显示越界了。

所以我们在判断到最后一个区域的时候要用倒数第二个区域的最后一行。。


#warning Potentially incomplete method implementation.

    // Return the number of sections.

   return 1;

}

// 分区中有几行

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

#warning Incomplete method implementation.

    // Return the number of rows in the section.

   return x;//是需要创建cell 的个数。

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath


//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

这个方法时候经常回出现bage 把forindexpath拿掉就可以实现了



重用机制   

    //查看使用过的cell中是否you空闲着没用的的cell,重用。

   static NSString *CellIdentifier =@"Cell";

//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

   UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];//判断是否有闲置的cell 

   if(!cell){

        cell =[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];

       //创建cell

    }

   NSString *string=[NSStringstringWithFormat:@"%@+%d",cell.textLabel.text,indexPath.row+1];

    cell.textLabel.text=string;

   NSLog(@"%d",indexPath.row);


UItableviewcell  :  image     label       accessory(指示条)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值