最親愛的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方法會爲你做。 –