I just wanted to do performances test on iOS on my project, and I am a little bit surprised of this behaviour :
In a simple SingleView Application, if I add 1000 UITextField
on rect (20, 20, 200, 200) from the viewDidLoad
: main controller method, it works great. It's stupid, but it works.
Now i create my class "MyTextField
" inherited from UITextField
and that implements drawRect: . The drawRect: implementation does nothing and i'm not overriding any other methods of UITextField
. I replace my 1000 UITextField
with MyTextField
class, and surprise : it crashes. Worse, my iPhone reboots !
I don't understand why. According to the Apple documentation, my drawRect does not need to call super. I also try to call super drawRect:
but the result is the same. Reboot due to "Receive memory warning
".
Is there an explanation to this please ?
EDIT : to be clear :
It crashed (and my iPhone reboots) :
@implementation MyTextField
-(void)drawRect:(CGRect)rect {
[super drawRect:rect];
}
@end
It crashed too (and my iPhone reboots) :
@implementation MyTextField
-(void)drawRect:(CGRect)rect {
// or does nothing
}
@end
It works :
@implementation MyTextField
@end
Here is my ViewController :
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"######### START ###########");
for (int i = 0 ; i < 1000 ; i++) {
MyTextField *tf = [[MyTextField alloc] initWithFrame:CGRectMake(20, 20, 200, 200)];
[self.view addSubview:tf];
}
NSLog(@"######### END ###########");
}
It does nothing else