-(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 *",并带有 arc
尝试使用以下代码:
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 位,根据平台的不同,编译器建议将强制转换添加到 long。