UITableView 关键操作

一、添加UITableViewCell为自己设计的风格

 

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

{

//两个section cell id要不同

if(indexPath.section == 0)

{

NSString *CellIdentifier = [NSString stringWithFormat:@"cell%d",indexPath.row];

NSLog(@"willAnimateRotationToInterfaceOrientation === TQDownViewCell");

TQDownViewCell *cell = (TQDownViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)

{

cell = [[[TQDownViewCell alloc] initWithFrame:CGRectMake(0, 0, m_downView.frame.size.width, TQDOWNCELL_HEIGHT) reuseIdentifier:CellIdentifier] autorelease];

}

cell.selectionStyle = UITableViewCellSelectionStyleNone;

TQDownItem *item = [[TQDownList shareInstance] taskAtIndex:indexPath.row];

cell.downItem = item;

return cell;

}else if(indexPath.section == 1)

{

NSString *CellIdentifier = [NSString stringWithFormat:@"cell_2%d",indexPath.row];

NSLog(@"willAnimateRotationToInterfaceOrientation === TQDownViewBackInfoCell");

TQDownViewBackInfoCell *backCell = (TQDownViewBackInfoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (backCell == nil)

{

backCell = [[[TQDownViewBackInfoCell alloc] initWithFrame:CGRectMake(0, 0, m_downView.frame.size.width, TQDOWNCELL_HEIGHT) reuseIdentifier:CellIdentifier] autorelease];

}

backCell.selectionStyle = UITableViewCellSelectionStyleNone;

TQVideoDownItem *item = [[TQDownList shareInstance] getCurrentBackgroupDownInfo];

if(item)

{

m_currenBackInfoNum = 1;

backCell.downItem = item;

}else

{

m_currenBackInfoNum = 0;

backCell.downItem = nil;

}

return backCell;

}

return nil;

}

二。修改UITableView的footer 和 head 

 

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

{

if (section == 0) {

CGRect screenRect = [[UIScreen mainScreen] applicationFrame];

UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 310, screenRect.size.height)];

footerView.autoresizesSubviews = YES;

footerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

footerView.userInteractionEnabled = YES;

footerView.hidden = NO;

footerView.multipleTouchEnabled = NO;

footerView.opaque  = NO;

footerView.contentMode = UIViewContentModeScaleToFill;

UILabel* footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 9, 300, 60.0)];

footerLabel.backgroundColor = [UIColor clearColor];

footerLabel.opaque = NO;

footerLabel.text = _(@"RSS Description");

footerLabel.textColor = [UIColor lightGrayColor];

footerLabel.font = [UIFont systemFontOfSize:17];

footerLabel.numberOfLines = 10;

[footerView addSubview:footerLabel];

[footerLabel release];

//return _(@"RSS Description");

return footerView;

}

return nil;

}

三、允许对cell进行编辑(删除、拖动等)

-(BOOL)tableView:(UITableView *) tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

//打开编辑

return YES;

}

- (void)setEditing:(BOOL)e animated:(BOOL)ani

{

[super setEditing:e animated:ani];

[mSpecialTableView setEditing:e animated:ani];//tableView 设置

if (e) self.editButtonItem.title = _(@"done");

else self.editButtonItem.title = _(@"edit");

}

 

//tableView 中cell选中事件

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

NSInteger specialIndex = [[TQDownList shareInstance] getCurSepcailIndex:indexPath.row];

NSString *strKey = [[TQDownList shareInstance] getCurRowIndex:specialIndex];

TQDownViewSecondPage *taskPage = [[TQDownViewSecondPage alloc] init];

[taskPage setSpecialKey:strKey];

[self.navigationController pushViewController:taskPage animated:YES];

[taskPage release];

}

 

//编辑tableView 时调整cell view里的控件位置

- (void)layoutSubviews

{

#define REDUCE_LEN 59

int tag = 25;

if (self.editing) 

{

//编辑时的位置

} else 

{

//默认位置 

}

[super layoutSubviews];

}

 

四、允许cell之间的拖动

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

{

//允许移动

return YES;

//return NO;

}

 

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

{

//交换数据

}

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值