UITableViewCell ----- Cell视图和文件的删除

  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

pragma tableView--delegate

pragma tableView

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.arrayData.count;
}

  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    return 87;
    }

  • (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
    {
    UIView *view =[[ UIView alloc] init];
    view.backgroundColor = [UIColor colorWithRed:0.16 green:0.17 blue:0.21 alpha:0.2];
    return view;
    }

  • (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
    {
    return 0.5;
    }

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"PDFTableViewCell";
KGCBaikePDF *model = [self.arrayData objectAtIndex:indexPath.row];
PDFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"PDFTableViewCell" owner:nil options:nil];
cell = [nibs lastObject];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
[cell KGCBaikePDFload:model];
return cell;
}

  • (BOOL)tableView: (UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
    }

  • (BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
    }

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

KGCBaikePDF *model = [self.arrayData objectAtIndex:indexPath.row];
[self.arrayData removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]  withRowAnimation:UITableViewRowAnimationRight];
[tableView setEditing:NO animated:YES];
[self cleanDownloadFiles:model.strName];
//删除数据库
[BaiDataBase jq_inDatabase:^{
    NSString *sql = [NSString stringWithFormat:@"where strName = '%@'",model.strName];
    [BaiDataBase jq_deleteTable:KGCNAMEPDF whereFormat:sql];
}];
[self initData];

}

  • (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    return @"删除";
    }

//清空可以根据这个去清空
-(void)cleanDownloadFiles:(NSString *)file
{
NSString *full = [[self cachesDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.pdf",[self transform:file]]];
NSFileManager *fileManager = [[NSFileManager alloc] init];
if ([fileManager fileExistsAtPath:full]) {
NSError *removeError = nil;
if ([fileManager removeItemAtPath:full error:&removeError]) {
[self.view showToastMessage:@"删除完成"];
}
if (removeError)
{
[self.view showToastMessage:@"删除失败"];
}
}
}

//获取文件的位置 沙盒
-(NSString *)cachesDirectory
{
return [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0] stringByAppendingPathComponent:[PersonInfo getPersonInfo].passport];
}

  • (NSString *)transform:(NSString *)chinese
    {
    NSMutableString *pinyin = [chinese mutableCopy];
    CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformMandarinLatin, NO);
    CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformStripCombiningMarks, NO);
    return [pinyin uppercaseString];
    }

/*

pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    }
    */

@end

你可能感兴趣的:(UITableViewCell ----- Cell视图和文件的删除)