一、添加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
{
//交换数据
}