// _imageURL = [imageURLS retain];
_request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://avatar.csdn.net/2/C/D/1_totogo2010.jpg"]];
_conn = [[NSURLConnection alloc] initWithRequest:_request delegate:self];
_incrementallyimgSource = CGImageSourceCreateIncremental(NULL);
_recieveData = [[NSMutableData alloc] init];
_isLoadFinished = false;
view = [[UIImageView alloc] initWithFrame:CGRectMake(10,10, 300, 300)];
view.image = self.image;
SEL ors = @selector(method1);
SEL news = @selector(method2);
Class c = NSClassFromString(@"ViewController");
BOOL succesed = swizzle(c,ors,news);
[self method2];
NSLog(@"succesed :%d",succesed);
}
BOOL swizzle(Class c,SEL origSelector, SEL newSelector)
{
Method origMethod = class_getInstanceMethod(c, origSelector);
Method newMethod = class_getInstanceMethod(c, newSelector);
if (origMethod && newMethod) {
if (class_addMethod(c, origSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) {
class_replaceMethod(c, newSelector, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
} else {
method_exchangeImplementations(origMethod, newMethod);
}
return YES;
}
return NO;
}
- (void)method1{
[self.view addSubview:view];
NSLog(@" method1 ");
}
- (void)method2{
NSLog(@" method2 ");
}