重新加载部分无法正常处理

时间:2018-01-28 05:57:24

标签: objective-c xcode uitableview

我有以下实现,其中$db->abcd和表格单元格上有两个按钮(标题为#!/usr/bin/env groovy pipeline { agent any parameters { string(defaultValue: '', description: 'Delivery name', name: 'DELIVERY') choice(choices:'DEV1\nDEV2\nDEV3',description: 'Select Source environment', name: 'SOURCE_ENV') choice(choices:'TEST1\nTEST2\nTEST3',description: 'Select target environment', name: 'TERGET_ENV') choice(choices:'Yes\nNo',description: 'Generate Report?', name: 'GENREPORT') } stages { stage("Start Batch") { steps { bat ''' echo '${params.DELIVERY}' echo '${params.SOURCE_ENV}' echo '${params.TERGET_ENV}' echo '${params.GENREPORT}' cd "C:\\Users\\DELIVERY_BATCH\\src" cscript.exe DELEXCEBATCH.vbs "C:\\Users\\Documents\\BatchFiles" ${params.DELIVERY} ${params.SOURCE_ENV} ${params.TERGET_ENV} ${params.GENREPORT} EXIT /B 0 ''' } } stage("Create Summary Excel sheet") { steps { bat ''' echo 'Batch Execution is successful' ''' } } } } title)。当用户选择并关闭该部分并再次打开时,他只会看到按钮标题的默认值half而不是他的选择。

我能够看到以下方法(full )在重新加载期间被调用,但它没有任何效果。

代码和截图如下。

full

1 个答案:

答案 0 :(得分:2)

您正在从setHalfButton数据源方法调用setFullButtoncellForRowAtIndexPath:函数,但它们正在调用cellForRowAtIndexPath: tableview方法。由于您还没有从前一种方法返回单元格,后一种方法会将nil返回cell,导致无法更新。

setHalfButtonsetFullButton方法应该在ComboTableViewCell类中:

-(void) setHalfButton 
{
    [self.halfBtnOutlet setTitleColor:[UIColor colorWithRed:0 green:102.0f/255.0f blue:0 alpha:1] forState:UIControlStateNormal];
    [self.fullBtnOutlet setTitleColor:[UIColor colorWithRed:0.5f green:0.5f blue:0.5f alpha:1] forState:UIControlStateNormal];
    [self.halfBtnOutlet.titleLabel setFont:[UIFont boldSystemFontOfSize:15.f]];
    [self.fullBtnOutlet.titleLabel setFont:[UIFont systemFontOfSize:15.f]];
}

-(void) setFullButton
{
    [self.fullBtnOutlet setTitleColor:[UIColor colorWithRed:0 green:102.0f/255.0f blue:0 alpha:1] forState:UIControlStateNormal];
    [self.halfBtnOutlet setTitleColor:[UIColor colorWithRed:0.5f green:0.5f blue:0.5f alpha:1] forState:UIControlStateNormal];
    [self.fullBtnOutlet.titleLabel setFont:[UIFont boldSystemFontOfSize:15.f]];
    [self.halfBtnOutlet.titleLabel setFont:[UIFont systemFontOfSize:15.f]];
}

此外,每次出列单元格时都会添加按钮操作处理程序,但只应在分配新单元格时执行此操作。从设计的角度来看,这些按钮点击处理程序也应该在具有委托模式的ComboTableViewCell类中,以通知视图控制器半/完全被更改。

至少看起来应该是这样的:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{          
    static NSString *cellIdentifier = @"ComboCell";
    ComboTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil)
    {
        cell = [[ComboTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        [cell.halfBtnOutlet addTarget:self action:@selector(halfBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [cell.fullBtnOutlet addTarget:self action:@selector(fullBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    if([selectedRowsInSectionDictionary[@(indexPath.section)] containsObject: indexPath])
    {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
        if(
       comboItemsArray[indexPath.section].allComboItems[indexPath.row].pQuantity == 0.5)
         {
            // it comes here after reloading
             [cell setHalfButton];
         }
         else
         {
             [cell setFullButton];
         }
    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.halfBtnOutlet.hidden = YES;
        cell.fullBtnOutlet.hidden = YES;
    }
    cell.comboTitle.text =comboItemsArray[indexPath.section].allComboItems[indexPath.row].pName;


    return cell;
}