2015-04-02 67 views
0

如何解决这个错误(数据参数不被格式字符串使用)?如何解决这个错误的数据参数未使用的格式字符串?

这是我的代码:

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()错误显示。为什么它显示错误?

回答

1

由于方法stringWithFormat:在格式说明符和传递给它的参数个数之间具有一对一的关系。
在您的代码中,您正在编写@"MyDayJournal.plist"作为格式字符串,然后稍后将NSHomeDirectory()作为参数传递,但没有格式说明符来接收此输入。类似@"%@/MyDayJournal.plist"。你的代码应该像

NSString *path=[NSString stringWithFormat:@"%@/MyDayJournal.plist",NSHomeDirectory()]; 
+0

谢谢兄弟,它为我工作。 – Phanindra 2015-04-03 05:07:47

相关问题