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

{

//交換數據

}

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章