UIlabel成网址?

时间:2013-01-23 12:08:00

标签: iphone xcode cocoa webview

我使用此代码

创建了一个包含我的位置数据的uilabel
longitudedata.text = [NSString stringWithFormat:@"longitude=%f", location.coordinate.longitude];
speeddata.text = [NSString stringWithFormat:@"speed=%f", [location speed] * 2.2369];
altitudedata.text = [NSString stringWithFormat:@"altitude=%f", [location altitude]];

但现在我需要在网址中添加这些内容,以便将数据发送到我的服务器,但所有iv尝试过dos的工作:(

NSURL *myURL = [NSURL URLWithString:[@"http://servername/ldtracker.aspx?id=3&" stringByAppendingString:longitudedata.text]];

等等但这个dosnt工作,似乎iv尝试了一切

我是xcode的初学者,请帮助:)

2 个答案:

答案 0 :(得分:0)

UILabels不处理网址,你需要给他们一个NSString。 label.text = [NSString stringWithFormat:@“http://servername/ldtracker.aspx?id = 3&%@”,longitudedata.text];

如果我正确理解你的问题,这应该有用

答案 1 :(得分:0)

NSURL *myURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://servername/ldtracker.aspx?id=3&%@&%@%@",longitudedata.text,speeddata.text,altitudedata.text]];