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

StackOverflow https://stackoverflow.com/questions/19762789

Question

The following in viewWillAppear

    [SYPTableView setSeparatorInset:UIEdgeInsetsZero];

Works fine on iOS 7 but on 6.1 it raised the exception :

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

My purpose is to remove the cell border.

Was it helpful?

Solution

The separatorInset property is available on UITableView from iOS 7.0 and that's why you get the exception on iOS 6.1.

From the code you posted it looks like you want to remove the default inset introduced in iOS 7. Such inset is not present in iOS 6, so you only have to remove the inset in iOS 7.

You can check whether the table view responds to setSeparatorInset: doing

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

OTHER TIPS

If you are working in ios 6 etc use the following

 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 {

    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top