-(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; 错误是:' nsinteger'的隐式转换。 (又名' long')到' nsstring *'不允许使用弧
答案 0 :(得分:4)
尝试使用以下代码:
v.UserSelected = [NSString stringWithFormat:@"%ld",(long) rowSelected.row];
注意:如果您尝试将值设置为:
v.UserSelected = [NSString stringWithFormat:@"%d",rowSelected.row];
您将收到编译器警告:
NSInteger类型的值不应用作格式参数;添加一个显式的强制转换为' long'代替
如果在OS X(64位)上编译,则会收到此警告,因为在该平台上,NSInteger被定义为long并且是64位整数。另一方面,%d格式用于int,即32位。因此格式和实际参数的大小不匹配。
由于NSInteger是32位或64位,因此根据平台的不同,编译器建议通常添加一个强制转换。