Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 基本-如何更改导入的库_Ios_Objective C_Subclass - Fatal编程技术网

Ios 基本-如何更改导入的库

Ios 基本-如何更改导入的库,ios,objective-c,subclass,Ios,Objective C,Subclass,我想使用在CocoaControls上找到的名为SDNestedTable的控件: 我已经对SDNestedTableViewController类进行了子类化,但是我想更改表格单元格的背景色,没有提供这样做的方法 库中的其他类是SDGroupCell和SDSubCell,它们继承自SDSelectableCellSDSelectableCell包含3种根据单元格状态更改背景的方法 以下是SDSelectableCell.m中的相关方法: - (void) styleEnabled {

我想使用在CocoaControls上找到的名为SDNestedTable的控件:

我已经对
SDNestedTableViewController
类进行了子类化,但是我想更改表格单元格的背景色,没有提供这样做的方法

库中的其他类是
SDGroupCell
SDSubCell
,它们继承自
SDSelectableCell
SDSelectableCell
包含3种根据单元格状态更改背景的方法

以下是
SDSelectableCell.m
中的相关方法:

- (void) styleEnabled
{
    for (UIView *view in checkBox.subviews) [view removeFromSuperview];
    [checkBox addSubview:onCheckBox];
    checkBox.alpha = 1.0;
    itemText.alpha = 1.0;
    self.backgroundView.backgroundColor = UIColorFromRGBWithAlpha(0x0d2e4d, 1.0);
}

- (void) styleDisabled
{
    for (UIView *view in checkBox.subviews) [view removeFromSuperview];
    [checkBox addSubview:offCheckBox];
    checkBox.alpha = 1.0;
    itemText.alpha = 0.4;
    self.backgroundView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:1.0];
}

- (void) styleHalfEnabled
{
    for (UIView *view in checkBox.subviews) [view removeFromSuperview];
    [checkBox addSubview:onCheckBox];
    checkBox.alpha = 0.45;
    itemText.alpha = 0.7;
    self.backgroundView.backgroundColor = UIColorFromRGBWithAlpha(  , 1.0);
}

我可以看到两种方法,但我是新手,希望验证处理此问题的最佳方法:

1) 只需更改SDSelectableCell.m中的代码。我必须更改3行来设置3种颜色,然后我就完成了。然而,我认为像这样导入库并仅仅更改代码是不好的做法。如果某个项目的工作人员不得不重新导入库而不知道库已更改,我可以预见将来会出现问题

1a)我想我也可以重命名/重构所有内容,使其不再是SD,这至少可以防止其他人认为它是原始的SDNestedTable库

2) 我可以子类化
SDSelectableCell
并覆盖这3个方法。虽然,这需要我对库中的每个其他类进行子类化,因为它们实例化了SDCell,我必须改变所有这些


3) 还有别的办法吗?类别和扩展似乎不起作用,但可能我遗漏了一些东西。

在快速查看github代码之后,看起来它们为您提供了一种简单的方法,可以按照您喜欢的方式设置单元格。在
SDNestedTableDelegate
中,实现
-mainTable:itemDidChange:
方法

- (void)mainTable:(UITableView *)mainTable itemDidChange:(SDGroupCell *)item
{
    SelectableCellState state = item.selectableCellState;
    switch (state) {
        case Checked:
            item.backgroundView.backgroundColor = [UIColor ...];
            break;
        case Unchecked:
            item.backgroundView.backgroundColor = [UIColor ...];
            break;
        case Halfchecked:
            item.backgroundView.backgroundColor = [UIColor ...];
            break;
        default:
            break;
    }
}

更新

当您通过重写
-mainTable:setItem:forRowAtIndexPath:
-item:setSubItem:forRowAtIndexPath:
SDNestedTableViewController
进行子类化时,该库似乎为您提供了格式化项和子项的位置。将其与上述项目结合起来,可以更改代码并提取常见功能,从而为您提供:

- (void)PRIVATE_finalizeSelectableCell:(SDSelectableCell *)item
{
    SelectableCellState state = item.selectableCellState;
    switch (state) {
        case Checked:
            item.backgroundView.backgroundColor = [UIColor ...];
            break;
        case Unchecked:
            item.backgroundView.backgroundColor = [UIColor ...];
            break;
        case Halfchecked:
            item.backgroundView.backgroundColor = [UIColor ...];
            break;
        default:
            break;
    }
}
- (void)mainTable:(UITableView *)mainTable itemDidChange:(SDGroupCell *)item
{
    [self PRIVATE_finalizeSelectableCell:item];
}
- (SDGroupCell *)mainTable:(UITableView *)mainTable setItem:(SDGroupCell *)item forRowAtIndexPath:(NSIndexPath *)indexPath 
{
    [self PRIVATE_finalizeSelectableCell:item];
    return item;
}
- (SDSubCell *)item:(SDGroupCell *)item setSubItem:(SDSubCell *)subItem forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self PRIVATE_finalizeSelectableCell:subItem];
    return subItem;
}

但这只会在状态更改时更改颜色,而不会在初始化时更改颜色。