我尝试使用UrlString调用Web服务但不确定如何调用它?我知道我需要放置代码的一部分,但不知道如何编码。我的.m文件的编码如下。如果有人能够对它有所了解或者有一个工作的例子会有很多帮助(阅读相当多的网页,现在到了突破点!)
@implementation ViewController
@synthesize characterimage;
@synthesize characterpicker;
@synthesize characters = _characters;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Load up NSArray
_characters = [[NSArray alloc] initWithObjects:@"bergerac" , @"biarritz" , @"chareleroi" , @"liege" , @"oostende" , nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - UIPickerView Methods
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return _characters.count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [_characters objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
//Create UIImage
UIImage *bergeracimage = [UIImage imageNamed:@"Bergerac.JPG"];
UIImage *biarritizimage = [UIImage imageNamed:@"Biarritz-Anglet-Bayonne_Airport_view_from_landing_strip.jpg"];
UIImage *chareleroiimage = [UIImage imageNamed:@"Aéroport_de_Charleroi,_B737_Ryanair_-_2011.JPG"];
UIImage *liegeimage = [UIImage imageNamed:@"Liege_airport.jpg"];
UIImage *oostendeimage = [UIImage imageNamed:@"Luchthavengebouw_Antwerpen-Deurne.jpg"];
switch (row) {
case 0:
characterimage.image = bergeracimage;
self.urlString = @"http://www.google.com";
break;
case 1:
characterimage.image = biarritizimage;
break;
case 2:
characterimage.image = chareleroiimage;
break;
case 3:
characterimage.image = liegeimage;
break;
case 4:
characterimage.image = oostendeimage;
break;
default:
characterimage.image = oostendeimage;
break;
}
}
- (IBAction)buttontapped:(UIButton *)sender
{
//call your web service with self.urlString
}
@end
答案 0 :(得分:0)
首先,您无法使用简单的url字符串调用Web服务。您需要使用Apple提供的一些api来调用Web服务。
您可以查看此示例:http://codewithchris.com/tutorial-how-to-use-ios-nsurlconnection-by-example/
这篇文章解释了如何使用NSURLConnection进行同步和异步请求。
另外,您可以通过NSURLConnection类参考。苹果给出了一些例子。