stringByAppendingString

jas*_*son 5 iphone xcode tableview

我正在使用Xcode 4.2故事板.我被困在这个连接中.这是正确的吗?我要修改的代码在哪里?实际上我想显示一个新的tableview,具体取决于从上一个tableview传递的变量("row").任何帮助赞赏.

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];
Run Code Online (Sandbox Code Playgroud)

zap*_*aph 7

由于self.newRow是整数,因此将代码更改为:

NSString *urlStr = [urlString stringByAppendingFormat:@"%i", self.newrow];
Run Code Online (Sandbox Code Playgroud)

格式将整数转换为字符串表示形式.

几个陈述可以合并而不会失去清晰度:

NSString *urlString = [NSString stringWithFormat: @"http://ipaddress/iphone.php?id=%i", self.newrow];
Run Code Online (Sandbox Code Playgroud)