iOS 自定义UItableViewCell.
1、首先新建View
2、将Table View cell 控件拖入View
3、自定义Table View Cell 的identifier
4、设计自己的Table View Cell
5、在UItableView 方法中声明使用自己自定义的Cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CustomCellIdentifier = @"CustomCellIdentifier"; //CustomCellIdentifier 为自己自定义的cell identifier static BOOL nibsRegistered = NO; if (!nibsRegistered) { UINib *nib; if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPad) { nib=[UINib nibWithNibName:@"UIDownLoadCell_ipad" bundle:nil]; }else{ nib=[UINib nibWithNibName:@"UIDownLoadCell_iphone" bundle:nil]; } [tableView registerNib:nib forCellReuseIdentifier:CustomCellIdentifier]; nibsRegistered = YES; } UIDownLoadCell *cell = [tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier]; //分别设置自己在Cell 中添加的控件。 [cell.areaname setText:[self.areanames objectAtIndex:indexPath.row]]; [cell.progress setHidden:YES ]; NSString * url=[NSString stringWithFormat:@"%@%@",hostUrl,[self.downLoadUrl objectAtIndex:indexPath.row]]; cell.downloader=[[DWDownloader alloc]initWithPerpeties:url localFile:[self.downLoadUrl objectAtIndex:indexPath.row] threadCount:1]; [cell.downLoad addTarget:cell action:@selector(startDownLoad:) forControlEvents:UIControlEventTouchUpInside]; [self.allCells setObject:cell forKey:[self.downLoadUrl objectAtIndex:indexPath.row]]; if ([cell.areaname.text hasPrefix:@"浙江省"]&&[cell.areaname.text hasSuffix:@")"]) { [cell.downLoad setBackgroundImage:self.hasDownLoadImg forState:UIControlStateNormal]; [cell.downLoad setEnabled:NO]; }else if(![cell.areaname.text hasPrefix:@"浙江省"]&&[cell.areaname.text hasSuffix:@")"]){ [cell.downLoad setBackgroundImage:self.deleteImgImg forState:UIControlStateNormal]; } return cell; }
相关推荐
Terminator0 2020-02-19
WintonTalks 2012-07-16
莫封洛 2019-07-26
我的iOS王者之路 2019-06-28
MoMo 2017-01-10
Rephontil 2015-08-10
MinggeQingchun 2015-07-13
NineYao 2015-01-30
liuwentao 2013-09-13
wsmrcool 2013-01-17
SoccerZZM 2012-10-15
NineYao 2012-09-05
NineYao 2012-07-16
heqiang0 2020-06-25
wenxuegeng 2020-06-10
tenvainvi 2020-06-09