2014-02-12 167 views
-2

发送URL有PrintHello这是我的代码如何从其他文件

在PrintHello.h

@interface PrintHello : UIViewController 

-(void)Print; 

@end 

和PrintHello.m

-(void)Print 
{ 

    [self URL]; 

} 

-(void)URL 
{ 
    NSString *strURL=[NSString stringWithFormat:@"http://arproject.site90.com/jsonbuilding.php"]; 
    NSLog(@"%@",strURL); 
} 

在viewcontroller.m

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.printMessage = [[PrintHello alloc]init]; 
} 

-(IBAction)Button01 
{ 
    NSString *url=[self.printMessage Print]; 
    NSString *strURL=[NSString stringWithFormat:@"%@",url]; 
    NSLog(@"%@",strURL); 
} 

我误解了什么 我想从PrintHello发送url 我需要做什么? 请帮忙 谢谢

+0

问题不清楚。 – Pawan

+0

如何将PrintHello切换到viewcontroller? – Seeker

+0

嘿检查返回类型。 –

回答

2

首先我不明白为什么PrintHello是从UIViewController派生;它看起来像NSObject会做,其次你实际上并没有从你的方法返回任何东西(第三,方法名应该以小写字母开始,按照惯例):

@interface PrintHello : NSObject 

- (NSURL *)print; 

@end 

@implementation PrintHello 

- (NSURL *)print 
{ 
    return [self url]; 
} 

- (NSURL *)url 
{ 
    NSString *strURL = @"http://arproject.site90.com/jsonbuilding.php"; 
    NSLog(@"%@",strURL); 
    return [NSURL URLWithString:strURL]; 
} 
+0

非常感谢您的帮助。 – roboticca

0
-(void)URL{ 

} 

实际上应该返回类型NSURL而不是虚空。