2012-07-25 90 views

回答

1

只需重新實現它:

+ (UIColor *)groupTableViewBackgroundColor { 
    return mySpecialColor; 
} 

,當你做到這一點它會被覆蓋。

編輯:這似乎沒有一直在努力(儘管它應該這樣做!),所以這裏的改變方法的返回值的真正準系統方法混寫的實現:

#import <objc/runtime.h> 
#import <objc/message.h> 

UIColor *modified(Class __self, SEL __cmd) 
{ 
    return someOtherColor; 
} 

Class clazz = [UIColor class]; 
static IMP original; 
Method m = class_getClassMethod(clazz, @selector(groupTableViewBackgroundColor)); 
original = method_setImplementation(m, (IMP)modified); 

這所有工作都應在初始化期間儘早完成

+0

非常感謝。他們會這樣做: – 2012-07-25 18:55:13

+0

tableView.backgroundColor = [UIColor groupTableViewBackgroundColor]; - 但這只是返回默認的背景色。 – 2012-07-25 19:02:46

+0

如果這不起作用(儘管它應該),您可以使用方法swizzling來更改此特定方法的實現。 – 2012-07-25 19:10:32