我正在尝试遵循如何拦截 UITextView 中的点击链接中接受的答案中的建议?,但我设法让自己很困惑,部分原因是我不太了解委托,到现在我已经添加和删除了很多我不知道发生了什么的事情。
这是GHFeedback.h
:
#import <UIKit/UIKit.h>
#import "GHApplicationSubclassed.h"
@interface GHFeedback : UIViewController <UIApplicationDelegate>
@property (nonatomic, strong) UITextView *feedbackInstructions;
@property (nonatomic, strong) GHApplicationSubclassed *ghAppSub;
@end
这是GHFeedback.m
:
#import "GHFeedback.h"
#import <MessageUI/MessageUI.h>
#import "GHApplicationSubclassed.h"
@interface GHFeedback () <UIApplicationDelegate, MFMailComposeViewControllerDelegate>
@end
@implementation GHFeedback
@synthesize feedbackInstructions, ghAppSub;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.ghAppSub.delegate=self;
}
return self;
}
-(void)openURL:(NSURL *)url //This is the method I'm trying to add--the text set for self.feedbackInstructions in IB contains an email address, and I want a subject line to appear automatically if the user sends an email.
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"feedback on Haiku"];
[self presentViewController:mailer animated:YES completion:NULL];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
这是GHApplicationSubclassed.h
:
#import <UIKit/UIKit.h>
@interface GHApplicationSubclassed : UIApplication <UIApplicationDelegate>
@property (nonatomic, strong) GHApplicationSubclassed *appli;
@end
这是GHApplicationSubclassed.m
:
#import "GHApplicationSubclassed.h"
@implementation GHApplicationSubclassed
@synthesize appli;
-(BOOL)openURL:(NSURL *)url
{
if ([self.delegate openURL:url]) //This line gets an error, "no known instance method for selector 'openURL'
return YES;
else
return [super openURL:url];
}
@end
我很想明确说明如何解决这个问题。(“显式”是指,与其说“然后实现委托方法”,不如说“然后将此方法添加到GHFeedback.m
: -(void)openURL {[actual methods, etc., etc.]}
.
非常感谢你的帮助。
编辑:我想要发生的是这个。
UITextView
视图控制器中显示的内容GHFeedback
是“如果您对应用程序有任何疑问/问题,请给我发电子邮件”,然后提供我的电子邮件地址。现在,当用户按下该电子邮件地址时,iOS 邮件程序会打开一封空的草稿电子邮件。我想提供打开自动主题行“对俳句的反馈”的电子邮件草稿。