Quote:
|
[button removeFromSuperview]
|
Indeed this does solve the problem when you get the strange error:
Quote:
|
modifying layer that is being finalized
|
In my case, the button I was creating was actually in a seperate thread than the main thread. Along with that, the button was being created in a thread that was executing opengl.
My aim was to use a custom Edit box with custom font and behavior, then use the UITextView to display the keyboard.
After a long and ardous journey of 3 days, filled with thread synchronization issues and other such niceties as UITextView not calling overloaded functions, and also not correctly sending touchEvents down the chain as expected, the final product was finally completed.
A completely independent text box that interacts with the UIKeyboard.
I have included the header file and the source file for reference. If anybody is interested in doing something similar, just hit me up.
Code:
#import <UIKit/UIKit.h>
#import <UIKit/UITextField.h>
//CLASS INTERFACE:
@interface SageTextField : UITextField <UITextFieldDelegate>
{
}
- (id)initWithCoder:(NSCoder *)inCoder;
- (id)initWithFrame:(CGRect)frame;
- (void)layoutSubviews;
@end
Code:
#import <SageTextField.h>
#import "SageImpl.h"
//CLASS IMPLEMENTATIONS:
@implementation SageTextField
- (id)initWithCoder:(NSCoder *)inCoder
{
if (self = [super initWithCoder:inCoder])
self.delegate = self;
self.text = @"initcoder";
return self;
}
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
self.delegate = self;
self.text = @"init";
return self;
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch;
CGPoint point;
//UIWindow* window = touch.window;
touch = [[touches allObjects] objectAtIndex:0];
point = [touch locationInView:self];
point.x += self.frame.origin.x;
point.y += self.frame.origin.y;
SageAddMessage(IPHONE_MSG_TOUCHBEGAN, &point, sizeof(point));
[super touchesBegan:touches withEvent:event];
}
- (void)layoutSubviews
{
// Do nothing - there are no subviews.
// Default method attempts to check for a URL in text and causes threading lock issues during render!?!
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch;
CGPoint point;
touch = [[touches allObjects] objectAtIndex:0];
point = [touch locationInView:self];
point.x += self.frame.origin.x;
point.y += self.frame.origin.y;
SageAddMessage(IPHONE_MSG_TOUCHMOVED, &point, sizeof(point));
[super touchesMoved:touches withEvent:event];
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch;
CGPoint point;
touch = [[touches allObjects] objectAtIndex:0];
point = [touch locationInView:self];
point.x += self.frame.origin.x;
point.y += self.frame.origin.y;
SageAddMessage(IPHONE_MSG_TOUCHENDED, &point, sizeof(point));
[super touchesEnded:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
// Touches ended no longer called on UITextView in SDK 3.0.
UITouch *touch;
CGPoint point;
touch = [[touches allObjects] objectAtIndex:0];
point = [touch locationInView:self];
point.x += self.frame.origin.x;
point.y += self.frame.origin.y;
SageAddMessage(IPHONE_MSG_TOUCHENDED, &point, sizeof(point));
[super touchesCancelled:touches withEvent:event];
}
- (void)dealloc
{
[super dealloc];
}
@end
I won't post the custom Text Editor class as it is far too much code, and it's all written in C++.
Also there are chunks of intermediate code segments that are written in a blend of Objective C and C++.