Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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
Objective c UI按钮滑动导致UITableViewCellAccessoryType出现问题_Objective C_Uibutton_Uitableview_Swizzling - Fatal编程技术网

Objective c UI按钮滑动导致UITableViewCellAccessoryType出现问题

Objective c UI按钮滑动导致UITableViewCellAccessoryType出现问题,objective-c,uibutton,uitableview,swizzling,Objective C,Uibutton,Uitableview,Swizzling,我有一个类,当buttonType为UIButtonTypeCustom为true时,它会Swizzle UIButton's。 但是,当涉及UITableViewCellAccessoryCheckmark和UITableViewCellAccessoryDisclosure时也是如此。发生的事情是,出于某种原因,它正在滑动它们,并出于某种原因在accessoryType后面添加自定义背景等等 我需要做的是检查我正在尝试swizzle的UIButton是否为UITableViewCellAcc

我有一个类,当buttonType为UIButtonTypeCustom为true时,它会Swizzle UIButton's。 但是,当涉及UITableViewCellAccessoryCheckmark和UITableViewCellAccessoryDisclosure时也是如此。发生的事情是,出于某种原因,它正在滑动它们,并出于某种原因在accessoryType后面添加自定义背景等等

我需要做的是检查我正在尝试swizzle的UIButton是否为UITableViewCellAccessoryType,但我不知道如何执行此操作

下面是我用来滑动UIButton的函数的内部结构


任何帮助都将不胜感激

我所做的快速修复可以实现我想要实现的目标

代码: 如果[self-isMemberOfClass:[UIButton类]]和&self.buttonType==UIButtonTypeCustom{

    if (![[self titleLabel] text]) {

    } else {

        UIImage *upImage = [theme rectButtonUp], *downImage = [theme rectButtonDown];
        UIColor *upColor = [theme rectButtonUpTextColor], *downColor = [theme rectButtonDownTextColor];

        /* If the highlighted title is set to _theme_asdf, look for a custom
         * button image called "asdf" and use that. Clear out this highlighted
         * title string. */

        NSString *hlTitle = [self titleForState:UIControlStateHighlighted];
        if ([hlTitle isEqualToString:@"_theme_add"] || [hlTitle isEqualToString:@"Add"]) {
            upImage = [theme rectButtonUpAdd];
            downImage = [theme rectButtonDownAdd];
        } else if ([hlTitle isEqualToString:@"_theme_remove"]) {
            upImage = [theme rectButtonUpRemove];
            downImage = [theme rectButtonDownRemove];
        } else {
            upImage = [theme rectButtonUp];
            downImage = [theme rectButtonDown];
        }

        [self setTitle:nil forState:UIControlStateHighlighted];
        upColor = [theme rectButtonUpTextColor];
        downColor = [theme rectButtonDownTextColor];

        [self setBackgroundImage:upImage forState:UIControlStateNormal];
        [self setBackgroundImage:downImage forState:UIControlStateHighlighted];
        [self setBackgroundImage:downImage forState:UIControlStateSelected];

        if (upColor) {
            [self setTitleColor:upColor forState:UIControlStateNormal];
            [self setTitleColor:[upColor colorByLighteningTo:0.5f] forState:UIControlStateDisabled];
        }
        if (downColor) {
            [self setTitleColor:downColor forState:UIControlStateHighlighted];
            [self setTitleColor:downColor forState:UIControlStateSelected];
        }
    }   
}

因此,基本上,所有UIButton都有一个带有文本的标题标签,但UITableViewCellAccessoryType没有。因此,我们取得了成功。这可能是一个黑客攻击,但现在它帮助我完成了我需要的任务。

对UIButton进行子类化,并在您想要滑动它时使用该类,以便只滑动新类?
    if (![[self titleLabel] text]) {

    } else {

        UIImage *upImage = [theme rectButtonUp], *downImage = [theme rectButtonDown];
        UIColor *upColor = [theme rectButtonUpTextColor], *downColor = [theme rectButtonDownTextColor];

        /* If the highlighted title is set to _theme_asdf, look for a custom
         * button image called "asdf" and use that. Clear out this highlighted
         * title string. */

        NSString *hlTitle = [self titleForState:UIControlStateHighlighted];
        if ([hlTitle isEqualToString:@"_theme_add"] || [hlTitle isEqualToString:@"Add"]) {
            upImage = [theme rectButtonUpAdd];
            downImage = [theme rectButtonDownAdd];
        } else if ([hlTitle isEqualToString:@"_theme_remove"]) {
            upImage = [theme rectButtonUpRemove];
            downImage = [theme rectButtonDownRemove];
        } else {
            upImage = [theme rectButtonUp];
            downImage = [theme rectButtonDown];
        }

        [self setTitle:nil forState:UIControlStateHighlighted];
        upColor = [theme rectButtonUpTextColor];
        downColor = [theme rectButtonDownTextColor];

        [self setBackgroundImage:upImage forState:UIControlStateNormal];
        [self setBackgroundImage:downImage forState:UIControlStateHighlighted];
        [self setBackgroundImage:downImage forState:UIControlStateSelected];

        if (upColor) {
            [self setTitleColor:upColor forState:UIControlStateNormal];
            [self setTitleColor:[upColor colorByLighteningTo:0.5f] forState:UIControlStateDisabled];
        }
        if (downColor) {
            [self setTitleColor:downColor forState:UIControlStateHighlighted];
            [self setTitleColor:downColor forState:UIControlStateSelected];
        }
    }   
}