2013-07-05 14 views
15

Próbowanie iOS 7 zrobił:błąd UIAppearance setTranslucent: Niedozwolony typ nieruchomości, c za wygląd seter, _installAppearanceSwizzleForSetter

[[UINavigationBar appearance] setTranslucent:NO]; 

Got awarii i błędów:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, c for appearance setter, _installAppearanceSwizzleForSetter:' 
*** First throw call stack: 
(0x16ad9b8 0x142e8b6 0x16ad7ab 0x72163d 0x724c34 0x169daca 0x169d8de 0x6c09 0x228ea9 0x2296e9 0x22ab5e 0x240a6c 0x240fd9 0x22c7d5 0x35a4906 0x35a4411 0x16293e5 0x162911b 0x1653b30 0x165310d 0x1652f3b 0x22a2b1 0x22c4eb 0x6f3d 0x1d0d725) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

Inne połączenia działają prawidłowo: np.

[[UINavigationBar appearance] setBarStyle: UIBarStyleBlack]; 

Kiedy ustawić przezroczystość lokalnie, to nie psuje:

[self.navigationController.navigationBar setTranslucent:NO]; 

Jestem zakładając ten jest specyficzny dla iOS 7, ale nie starał się samo w iOS 6 jeszcze.

+3

Moderatorzy Uwaga: My, jako wspólnota, nie zgodził się na tematy, które są pod NDA http://meta.stackexchange.com/questions/94465/should-moderators-enforce-ndas-for-software- sprzedawcy – kevmalek

Odpowiedz

17
[[UINavigationBar appearance] setTranslucent:NO] 

To nie jest dostępna na iOS 6.It jest dostępna tylko w iOS 7 kolejnych.

+12

Niedostępne również w ios7 – Dejell

0

Nie wiem, co z systemem iOS 7. Jednak w systemie iOS6, zgodnie z dokumentacją, nie można ustawić właściwości półprzezroczystości dla obiektu UIAppearance obiektu UINavigationBar. Jakiś czas to pokazuje wszystkie możliwości w autouzupełniania z nieobsługiwanym też

1

Oto kod do obejścia go. Problem polega na tym, że UIAppearance nie działa na typach BOOL. Nie powinno to być podstawą do odrzucenia aplikacji, ponieważ stosuje standardowe (choć hacky) procedury. Baw się dobrze.

@protocol _UITranslucentThingHack 
@property (nonatomic) BOOL translucent; 
@end 

@interface UIView (_UITranslucentAppearanceProxyHack) 
@property (nonatomic) NSNumber * translucentPropertyAsObject; 
@end 

@implementation UIView (_UITranslucentAppearanceProxyHack) 

-(void)setTranslucentPropertyAsObject:(NSNumber *)translucentPropertyAsObject { 
    if([self respondsToSelector:@selector(setTranslucent:)]) { 
     id<_UITranslucentThingHack> trans = (id)self; 
     trans.translucent = [translucentPropertyAsObject boolValue]; 
    } 
} 

-(NSNumber*)translucentPropertyAsObject { 
    if([self respondsToSelector:@selector(setTranslucent:)]) { 
     id<_UITranslucentThingHack> trans = (id)self; 
     return @(trans.translucent); 
    } 
    return nil; 
} 

@end 
1

Rozwiązałem go z własnej kategorii, dzięki czemu nadal mogę używać UIAppearance w sposób podobny do normalnego.

@interface UINavigationBar (MMTranlucenceUIAppearance) 
@property(nonatomic,assign,getter=isMMTranslucent) NSInteger LYTranslucent NS_AVAILABLE_IOS(3_0) UI_APPEARANCE_SELECTOR; // Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent 
@end 


@implementation UINavigationBar (MMTranlucenceUIAppearance) 

// it appears that UIAppearance fails with BOOL 
-(NSInteger)isMMTranslucent 
{ 
    return self.translucent ? 0 : 1; 
} 

-(void)setMMTranslucent:(NSInteger)translucent 
{ 
    self.translucent = (translucent == 0) ? NO : YES; 
} 

@end 
Powiązane problemy