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

2

5

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.

Planetary answered 4/11, 2013 at 6:38 Comment(0)
P
11

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];
}
Photodrama answered 4/11, 2013 at 6:41 Comment(11)
so what is the iOS 6.1 alternative ?Planetary
@Petronnel, I support both. My question was what is "something reasonable"Planetary
There's no such thing as a separator inset in iOS 6. If your purpose is to remove the default inset introduced in iOS 7, you can just do nothing in iOS 6, since by defaults there's no inset.Photodrama
My purpose was to remove the cell border. without this line the cell border will show up.Planetary
That's the wrong method for removing the cell border, read the documentation. You want instead to set the separatorStyle property to UITableViewCellSeparatorStyleNonePhotodrama
[SYPTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; removed the sperator only in iOS 7, in 6.1 it didn'tPlanetary
By the way, what's SYPTableView?Photodrama
@Petronella UITableView*Planetary
let us continue this discussion in chatPlanetary
Please follow the conventions and use lowercase names for variables. That being said, this question (why does setSeparatorInset: crash on iOS 6) has an answer. If you have a different question (why setting separatorStyle to UITableViewCellSeparatorStyleNone is not working), you should post it separately.Photodrama
what is the work around to be done in iOS 6 to look it similar to iOS 7. i.e, suppose if I have separator inset 64 points from left, how can i have one in iOS 6?Anachronism
I
0

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 {

    }
}
Irriguous answered 24/12, 2013 at 11:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.