2012-12-13 14 views
0

我试图按照How to intercept click on link in UITextView?的接受答案中的建议,但我设法让自己非常困惑,部分是因为我没有非常了解代表团,现在我已经添加并删除了很多东西,我不知道发生了什么。试图继承UIApplication并将其实施在委托中,但代表们感到困惑

这里的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.]}

非常感谢您的帮助。

编辑:我希望发生的就是这个

有在GHFeedback视图控制器,上面写着,显示UITextView“如果您有任何疑问/问题与应用程序,请给我发电子邮件,”然后给我的电子邮件地址。现在,当用户按下该电子邮件地址时,iOS邮件程序将打开一个空d筏邮件。我想给电子邮件草案打开一个“Haiku反馈”的自动主题。

+0

你能解释一下你想要发生什么吗?这可能会更容易地按照 – mkral

+0

完成。对不起,首先不清楚。 –

+0

另外,代表团通常比大多数人想象的要简单。假设我们在视图控制器中有一个类“Timer”。我们可以初始化一个'Timer'并启动定时器。想象一下,2分钟后时间结束。在'Timer'类中,我们可以设置一个委托方法来回调视图控制器,这样它就知道定时器已经完成,但是我们必须设置我们创建的Timer实例的'delegate',以便它知道什么类(我们的视图控制器在这种情况下)发送“timerDidFinish”方法。头文件中的只是帮助xcode知道类所设置的委托方法。 – mkral

回答

0
if ([self.delegate openURL:url]) 

openURL的返回类型是:void,所以实际上没有什么在这个if语句来检查。

也许你想使用

if ([(GHFeedback *)self.delegate respondsToSelector:@selector(openURL:)]{ 
    [(GHFeedback *)self.delegate openURL:url]; 
    return YES; 
} 

如果正确openURL:仍然不会被解雇,则必须self.delegate为零。

+0

如果是什么?如果是什么?我渴望知道! :) –

+0

@JoelDerfner他意味着'if'语句没有被解雇。不知道你是否在开玩笑,虽然 – mkral

+0

我添加了我的评论到这个答案的未完成版本,并以“if”结尾。所以我不是在开玩笑,而是追溯到现在。 :) –