2011-10-14 45 views
0

最親愛的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?&regno=%@", thisValue 
          ]; 

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: thisPlateURL]]; 

    [thisPlateURL release]; 
} 

我猜這件事情與我沒有設置正確thisValue,我敢肯定,我會如果有人發現它,我會踢自己,但我只是不明白問題所在。

請幫忙!

回答

2

我認爲這個問題是在的NSString初始化:

嘗試:

NSString* thisPlateURL = [NSString stringWithFormat: @"http://www.site.co.uk?&regno=%@", thisValue]; 
+0

,這樣不會需要釋放然後將它,因爲我還沒有說alloc或新? –

+0

我認爲你可以釋放thisPlateURl,因爲這是一個NSString對象的實例(當然是指向一個實例的指針)。你不會寫alloc或者new,但是靜態的NSString方法會爲你做。 –

0

你正在一個錯誤的方式初始化NSString - [NSString new],你應該使用[NSString alloc]代替