2016-04-19 72 views
-2
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 

if ([segue.identifier isEqualToString:@"mnuSelected"]) 
{ 
    ViewController *v = segue.destinationViewController; 

    if(self.searchDisplayController.active) { 
    NSIndexPath *indexPath = nil; 
    indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow]; 
    v.str = [self.result objectAtIndex:indexPath.row]; 
     NSIndexPath *rowSelected = nil; 
     rowSelected = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow]; 
     v.UserSelected = rowSelected.row; //error in this line 

} 
    else { 
    NSIndexPath *indexPath = nil; 
    indexPath = [self.tableView indexPathForSelectedRow]; 
    v.str = [self.monthName objectAtIndex:indexPath.row]; 
     NSIndexPath *rowSelected = nil; 
     rowSelected = [self.tableView indexPathForSelectedRow]; 
     v.UserSelected = rowSelected.row; 

} 
    return; } 
} 

我有錯誤在這條線:v.UserSelected = rowSelected.row; 錯誤是:(又名「長」)到「的NSString *」與圓弧不允許「NSInteger的」隱式轉換「NSInteger的」的隱式轉換(又名「長」),以「的NSString *」是不允許的弧形

+0

try v.UserSelected = [nsstring stringwithformat:@「%d」,rowSelected.row]; – iOS

+1

如何在'ViewController'中聲明'UserSelected'?據說'NSString'。爲什麼一個'NSString'?爲什麼不是'NSInteger'? – Larme

+0

UserSelected是一個? int,long,string?請在您的問題中指定它 –

回答

4

嘗試使用下面的代碼:

v.UserSelected = [NSString stringWithFormat:@"%ld",(long) rowSelected.row]; 

注:如果您嘗試設定值:

v.UserSelected = [NSString stringWithFormat:@"%d",rowSelected.row];

您將獲得編譯器警告:

不應將類型NSInteger的值用作格式參數;添加一個顯式的「長」,而不是

如果編譯在OS X(64位),因爲該平臺上NSInteger的定義爲長,是一個64位整數你得到此警告。另一方面,%d格式是32位的int。所以格式和實際參數大小不匹配。

由於NSInteger是32位或64位,因此根據平臺的不同,編譯器建議一般將長度加長。

相關問題