最亲爱的stackoverflow大脑,我在iOS上遇到了一些麻烦......我对这一切都很陌生。基于表单元的ios openURL单元格值
我试图打开一个网址的Safari浏览器,其中包括一个基于表格单元格的值的URL参数。所以如果表格单元格包含“堆栈”,我想去“http://stack.com?param=stack”。这应该是一个简单的任务,但我无法使其工作。
在我进入UIApplication产品线之前,这是失败的......所以我甚至不知道这是否会奏效。我得到这个错误:
2011-10-14 10:18:32.297 NPT[1085:207] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** initialization method -
initWithCharactersNoCopy:length:freeWhenDone: cannot be sent to an abstract object of
class NSCFString: Create a concrete instance!'
当我使用此代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString* thisValue = [[[self.searchResults cellForRowAtIndexPath:indexPath] textLabel] text];
NSString* thisPlateURL = [
[NSString new]
initWithFormat:@"http://www.site.co.uk?®no=%@", thisValue
];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: thisPlateURL]];
[thisPlateURL release];
}
我猜这件事情与我没有设置正确thisValue,我敢肯定,我会如果有人发现它,我会踢自己,但我只是不明白问题所在。
请帮忙!
,这样不会需要释放然后将它,因为我还没有说alloc或新? –
我认为你可以释放thisPlateURl,因为这是一个NSString对象的实例(当然是指向一个实例的指针)。你不会写alloc或者new,但是静态的NSString方法会为你做。 –