xcode stringByAppendingString
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8561160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
stringByAppendingString
提问by jason
I am using Xcode 4.2 storyboard. I am stuck in this concatenation. Is this right? Where in the code i've to modify? actually i want to display a new tableview depending on the variable passed ("row") from previous tableview. Any help appreciated.
我正在使用 Xcode 4.2 故事板。我被困在这个串联中。这是正确的吗?我必须修改代码中的哪个位置?实际上,我想根据从前一个 tableview 传递的变量(“row”)来显示一个新的 tableview。任何帮助表示赞赏。
self.newrow =row;// row is the variable passed from previous tableview
NSString *urlString = [NSString stringWithFormat: @"http://ipaddress/iphone.php?id="];
NSString *urlStr=@"";
urlStr=[urlString stringByAppendingString:newrow];
NSURL *url = [NSURL URLWithString:urlStr];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection release];
[request release];
回答by zaph
Since self.newRow
is an integer change your code to:
由于self.newRow
是整数,因此将您的代码更改为:
NSString *urlStr = [urlString stringByAppendingFormat:@"%i", self.newrow];
The format converts the integer to a string representation.
该格式将整数转换为字符串表示形式。
Several statements can be combined without loosing clarity:
可以将几个语句组合在一起而不会失去清晰度:
NSString *urlString = [NSString stringWithFormat: @"http://ipaddress/iphone.php?id=%i", self.newrow];