基于表格单元格值的ios openURL
最亲爱的 stackoverflow 大脑,我在使用 iOS 时又遇到了一些麻烦……不过我对这一切都是新手。
我正在尝试使用 url 打开 safari,其中包含基于表格单元格值的 URL 参数。因此,如果表格单元格包含“stack”,我想转到“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 有关,我确信如果有人发现它,我会踢自己,但我只是没有看到问题是什么。
请帮忙!
Dearest stackoverflow brains, I'm having some trouble with iOS again... I am new to this all though.
I'm trying to open a safari with a url, that includes a URL parameter based on the value of the table cell. So if the table cell contained "stack", I want to go to "http://stack.com?param=stack". This should be a simple task, but I'm having trouble getting it to work.
It's failing before I even get to the UIApplication line... so I don't even know if that will work. I'm getting this error:
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!'
When I use this code:
- (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];
}
I'm guessing it's something to do with me not setting thisValue properly, and I'm sure I'll kick myself if someone spots it, but I just don't see what the problem is.
Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题出在 NSString 初始化中:
尝试使用:
I think that the problem is in NSString initialization:
try with:
您以错误的方式初始化
NSString
-[NSString new]
,您应该使用[NSString alloc]
You are initializing
NSString
in a wrong way -[NSString new]
, you should use[NSString alloc]
instead