NSInvalidArgumentException',原因:' - [UITableView setSeparatorInset:]:发送到实例的无法识别的选择器

时间:2013-11-04 06:38:27

标签: ios objective-c unrecognized-selector

viewWillAppear中的以下内容

    [SYPTableView setSeparatorInset:UIEdgeInsetsZero];

在iOS 7上运行良好但在6.1上它引发了异常:

    NSInvalidArgumentException', reason: '-[UITableView setSeparatorInset:]: unrecognized selector sent to instance 

我的目的是删除单元格边框。

2 个答案:

答案 0 :(得分:11)

来自iOS 7.0的separatorInset上提供了UITableView属性,这就是您在iOS 6.1上获得例外的原因。

从您发布的代码中看起来您想要删除iOS 7中引入的默认插件。此类插件在iOS 6中不存在,因此您只需删除iOS 7中的插入内容。

您可以检查表格视图是否响应setSeparatorInset:正在进行

if ([SVPTableView respondsToSelector:@selector(setSeparatorInset:)]) {
    [SYPTableView setSeparatorInset:UIEdgeInsetsZero];
}

答案 1 :(得分:0)

如果您在ios 6等工作,请使用以下

 SEL selector;
 selector=NSSelectorFromString(@"setSeparatorInset:");
 if([table respondsToSelector:selector])
{
    @try {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSMethodSignature *aSignature;
            NSInvocation *anInvocation;
            aSignature=[table methodSignatureForSelector:selector];
            anInvocation=[NSInvocation invocationWithMethodSignature:aSignature];
            [anInvocation setSelector:selector];
            [anInvocation setTarget:table];
            UIEdgeInsets temp=UIEdgeInsetsZero;
            [anInvocation setArgument:&temp atIndex:2];
            [anInvocation invoke];
        });


    }
    @catch (NSException *exception) {
        NSLog(@"EXCEPTION WHILE CALLING Separator inset => %@",[exception userInfo]);
    }
    @finally {

    }
}
相关问题