如何解决格式字符串未使用的错误数据参数?
How to solve this Wrong Data argument not used by format String?
如何解决这个错误(格式字符串未使用数据参数)?
这是我的代码:
FOUNDATION_EXPORT NSString *NSHomeDirectory(void);
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
NSString *path=[NSString stringWithFormat:@"MyDayJournal.plist",NSHomeDirectory()];
NSFileManager *man=[NSFileManager defaultManager];
if([man fileExistsAtPath:path])
{
[dataArray exchangeObjectAtIndex:fromIndexPath.row withObjectAtIndex:toIndexPath.row];
}
[dataArray writeToFile:path atomically:YES];
[tableView1 reloadData];
}
NSHomeDirectory()
显示错误。为什么会显示错误?
因为方法 stringWithFormat:
在格式说明符和传递给它的参数数量之间具有一对一的关系。
在您的代码中,您正在编写 @"MyDayJournal.plist"
作为格式字符串,然后将 NSHomeDirectory()
作为参数传递,但是没有格式说明符来接收此输入。类似于 @"%@/MyDayJournal.plist"
。你的代码应该像
NSString *path=[NSString stringWithFormat:@"%@/MyDayJournal.plist",NSHomeDirectory()];
如何解决这个错误(格式字符串未使用数据参数)?
这是我的代码:
FOUNDATION_EXPORT NSString *NSHomeDirectory(void);
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
NSString *path=[NSString stringWithFormat:@"MyDayJournal.plist",NSHomeDirectory()];
NSFileManager *man=[NSFileManager defaultManager];
if([man fileExistsAtPath:path])
{
[dataArray exchangeObjectAtIndex:fromIndexPath.row withObjectAtIndex:toIndexPath.row];
}
[dataArray writeToFile:path atomically:YES];
[tableView1 reloadData];
}
NSHomeDirectory()
显示错误。为什么会显示错误?
因为方法 stringWithFormat:
在格式说明符和传递给它的参数数量之间具有一对一的关系。
在您的代码中,您正在编写 @"MyDayJournal.plist"
作为格式字符串,然后将 NSHomeDirectory()
作为参数传递,但是没有格式说明符来接收此输入。类似于 @"%@/MyDayJournal.plist"
。你的代码应该像
NSString *path=[NSString stringWithFormat:@"%@/MyDayJournal.plist",NSHomeDirectory()];