I'm trying to follow the suggestion in the accepted answer at How to intercept click on link in UITextView? , but I've managed to get myself very confused, partially because I don't understand delegation very well, and by now I've added and deleted so many things I have no idea what's going on.
Here's GHFeedback.h
:
#import <UIKit/UIKit.h>
#import "GHApplicationSubclassed.h"
@interface GHFeedback : UIViewController <UIApplicationDelegate>
@property (nonatomic, strong) UITextView *feedbackInstructions;
@property (nonatomic, strong) GHApplicationSubclassed *ghAppSub;
@end
Here's 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
Here's GHApplicationSubclassed.h
:
#import <UIKit/UIKit.h>
@interface GHApplicationSubclassed : UIApplication <UIApplicationDelegate>
@property (nonatomic, strong) GHApplicationSubclassed *appli;
@end
Here's 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
I'd love explicit instructions on how to fix this. (By "explicit" I mean that, rather than saying something like, "then implement the delegate method," you could say something like, "then add this method to GHFeedback.m
: -(void)openURL {[actual methods, etc., etc.]}
.
Thanks so much for your help.
EDIT: What I want to happen is this.
There's a UITextView
displayed in the view controller for GHFeedback
that says, "if you have any questions/problems with the app, please email me," and then gives my email address. Right now, when the user presses that email address, the iOS Mail program opens an empty draft email. I would like to give the draft email that opens an automatic subject line of "feedback on Haiku."