2011-05-06 26 views

回答

0

你在做什麼錯的是,

NSString *filePath=[[NSBundle mainBundle] pathForResource:@"%@",file_name ofType:@"txt"]; 

的而不是代碼,

NSString *filePath=[[NSBundle mainBundle] pathForResource:file_name ofType:@"txt"]; 
+0

謝謝。它的工作:) – sgoldman 2011-05-06 03:13:03

+0

@sgoldman:你歡迎:) – KingofBliss 2011-05-06 03:14:22

3

你可以簡單地傳遞變量。

NSString *filePath = [[NSBundle mainBundle] pathForResource:file_name ofType:@"txt"]; 

而且,由於要定義file_name是一個常量字符串,你不需要使用stringWithFormat:方法。你可以直接定義它。

NSString *file_name = @"Readme"; 

如果file_name變量將是自述每一次,那麼它的恆定,並不需要在所有定義:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Readme" ofType:@"txt"]; 
0
NSString *file_name = @"Readme.txt"; 

NSString *name = [file_name stringByDeletingPathExtension]; 
NSString *extension = [file_name pathExtension]; 

NSString *file_path = [[NSBundle mainBundle] pathForResource:name ofType:extension]; 
0
NSString *filePath=[[NSBundle mainBundle] pathForResource:@"Readme" ofType:@"txt"]; 
相關問題