我是 UITextView 的子类,并且我得到了它的工作,但我还想在调用 UITextView 委托方法时做一些额外的工作。这是我到目前为止所拥有的。
ThanaaTextView.h
#import <UIKit/UIKit.h>
#import "ThaanaDelegate.h"
@interface ThaanaTextView : UITextView {
@private
ThaanaDelegate * _thaanaDelegate;
}
ThanaaTextView.m
#import "ThaanaTextView.h"
@implementation ThaanaTextView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
//do some extra stuff to textview
//set delegate
self.delegate = _thaanaDelegate;
}
return self;
}
}
@end
这是我的代表课
ThaanaDelegate.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface ThaanaDelegate : NSObject <UITextViewDelegate> {
NSMutableArray* _lines;
}
+(NSString*) reverseText:(NSString*) text withFont:(UIFont*) font carretPosition:(NSRange*) cpos Lines:(NSMutableArray*) lines Bounds:(CGRect) bounds;
-(void) setText:(NSString*) txt textview:(UITextView *)textView;
@end
ThaanaDelegate.m
-(BOOL) textView:(UITextView*) textView shouldChangeTextInRange:(NSRange) range replacementText:(NSString*) text {
//delegate method i want to do things in
return NO;
}
-(void) setText:(NSString*) txt textview:(UITextView *)textView {
//stuff
return txt;
}
它编译并运行没有错误。但从不调用委托函数。我错过了什么。