Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move initialization code into a -commonInit method which is then call…

…ed from both -initWithFrame: and -initWithCoder: to allow EGOTextView to work when unarchived from a nib
  • Loading branch information...
commit 9dfde55f049868e463b19fba909d436ada4f13cd 1 parent 46e2b98
Mike Ash mikeash authored
Showing with 40 additions and 30 deletions.
  1. +40 −30 EGOTextView/EGOTextView.m
70 EGOTextView/EGOTextView.m
View
@@ -187,38 +187,41 @@ @implementation EGOTextView
@synthesize enablesReturnKeyAutomatically;
+- (void)commonInit {
+ [self setText:@""];
+ self.alwaysBounceVertical = YES;
+ self.editable = YES;
+ self.font = [UIFont systemFontOfSize:17];
+ self.backgroundColor = [UIColor whiteColor];
+ self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ self.clipsToBounds = YES;
+
+ EGOContentView *contentView = [[EGOContentView alloc] initWithFrame:CGRectInset(self.bounds, 8.0f, 8.0f)];
+ contentView.autoresizingMask = self.autoresizingMask;
+ contentView.delegate = self;
+ [self addSubview:contentView];
+ _textContentView = [contentView retain];
+ [contentView release];
+
+ UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
+ gesture.delegate = (id<UIGestureRecognizerDelegate>)self;
+ [self addGestureRecognizer:gesture];
+ [gesture release];
+ _longPress = gesture;
+
+ UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
+ [doubleTap setNumberOfTapsRequired:2];
+ [self addGestureRecognizer:doubleTap];
+ [doubleTap release];
+
+ UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
+ [self addGestureRecognizer:singleTap];
+ [singleTap release];
+}
+
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
-
- [self setText:@""];
- self.alwaysBounceVertical = YES;
- self.editable = YES;
- self.font = [UIFont systemFontOfSize:17];
- self.backgroundColor = [UIColor whiteColor];
- self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
-
- EGOContentView *contentView = [[EGOContentView alloc] initWithFrame:CGRectInset(self.bounds, 8.0f, 8.0f)];
- contentView.autoresizingMask = self.autoresizingMask;
- contentView.delegate = self;
- [self addSubview:contentView];
- _textContentView = [contentView retain];
- [contentView release];
-
- UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
- gesture.delegate = (id<UIGestureRecognizerDelegate>)self;
- [self addGestureRecognizer:gesture];
- [gesture release];
- _longPress = gesture;
-
- UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
- [doubleTap setNumberOfTapsRequired:2];
- [self addGestureRecognizer:doubleTap];
- [doubleTap release];
-
- UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
- [self addGestureRecognizer:singleTap];
- [singleTap release];
-
+ [self commonInit];
}
return self;
}
@@ -228,6 +231,13 @@ - (id)init {
return self;
}
+- (id)initWithCoder: (NSCoder *)aDecoder {
+ if ((self = [super initWithCoder: aDecoder])) {
+ [self commonInit];
+ }
+ return self;
+}
+
- (void)dealloc {
_textWindow=nil;
Please sign in to comment.
Something went wrong with that request. Please try again.