IOS疯狂基础之UITableView

滚动到指定行

NSIndexPath *lastRow = [NSIndexPath indexPathForRow:([self.loadedImages count] - 1inSection:0];

    [self.imagesTableView scrollToRowAtIndexPath:lastRow

                                atScrollPosition:UITableViewScrollPositionBottom

                                        animated:YES];


刷新某一行

NSIndexPath  *indexPath_1=[NSIndexPath indexPathForRow:1 inSection:0];

    NSArray      *indexArray=[NSArray  arrayWithObject:indexPath_1];

    [regTableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationNone];

选中某一行

NSIndexPath *ip=[NSIndexPath indexPathForRow:0 inSection:0];

    [self.table selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionBottom];


UITableView的常用使用步骤和注意点

1. h文件实现必要协议  

<UITableViewDataSource,UITableViewDelegate>


2. //代码创建载入   

UITableView

dataTabel = [[UITableViewalloc]initWithFrame:CGRectMake(10,45,300,self.view.bounds.size.height-65)style:UITableViewStylePlain];

    [dataTabel setDelegate:self];

    [ dataTabel  setDataSource : self ];
    //dataTabel.allowsSelection = NO; 不让选事件都不触发了
    [ self. view addSubview: dataTabel];
    [ dataTabel  reloadData ];

3.实现代理方法

#pragma TabelView

//指定有多少个分区(Section),默认为1

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;

}

//每个section显示的标题

- (NSString *)tableView:(UITableView *)tableViewtitleForHeaderInSection:(NSInteger)section{

    return @"";

}

//指定每个分区中有多少行,默认为1

- (NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section{

    return [nameArrcount];

}

//划动cell是否出现del按钮

- (BOOL)tableView:(UITableView *)tableViewcanEditRowAtIndexPath:(NSIndexPath *)indexPath {

    return NO;

}

//绘制Cell这个是主要的

-(UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *SimpleTableIdentifier =@"SimpleTableIdentifier";

    UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier: SimpleTableIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefault

                                      reuseIdentifier: SimpleTableIdentifier] ;

    }

    NSArray *subviews = [[NSArrayalloc]initWithArray:cell.contentView.subviews];//这个代码主要是防止点击时出现重复数据,这个是cell的重用机制

    for (UIView *subviewin subviews) {

        [subview removeFromSuperview];

    }

    。。。。。。

    return cell;

}

//改变行的高度

- (CGFloat)tableView:(UITableView *)tableViewheightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 90;

}

//选中Cell响应事件

- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPathanimated:YES];//选中后的反显颜色即刻消失

    。。。。。。

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值