हल (धन्यवाद Regexident)फ़ाइल नाम NSString अंतरिक्ष
मैं एक ऐप्लिकेशन है जो एक कस्टम -(id)init
init विधि करने के लिए एक पीडीएफ के फ़ाइल पथ गुजरता है में अनावश्यक% 20 कहते हैं। यह तालिका में जोड़ा जाता है और जब यह चयन किया जाता है, यह एक गैर विद्यमान फ़ाइल के लिए किसी और बयान कहता है:
- (void) gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index {
NSLog (@"Selected theArgument=%d\n", index);
UIViewController *viewController = [[[UIViewController alloc]init]autorelease];
{
//if file is built-in, read from the bundle
if (index <= 3)
{
// first section is our build-in documents
NSString *fileURLs = [_documentIconsURLs objectAtIndex:index];
NSLog(@"file url -%@", fileURLs);
viewController = [[[xSheetMusicViewController alloc]initWithContentURL:fileURLs]autorelease];
}
//if file is external, read from URL
else
{
// second section is the contents of the Documents folder
NSString *fileURL = [_documentIconsURLs objectAtIndex:index];
NSLog(@"file url -%@", fileURL);
NSString *path;
NSString *documentsDirectoryPath = [self applicationDocumentsDirectory];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileURL];
if ([[NSFileManager defaultManager] fileExistsAtPath:documentsDirectoryPath])
{
viewController = [[[xSheetMusicViewController alloc]initWithDocumentURL:fileURL]autorelease];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure!" message:@"The Selected File Does Not Exist"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
return;
}
}
[self.navigationController setNavigationBarHidden:YES animated:NO];
[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:YES];
[self.navigationController pushViewController:viewController animated:NO];
[UIView commitAnimations];
}
}
तो जब भी मैं इसे के नाम पर कोई जगह नहीं के साथ एक दस्तावेज़ है, यह धक्का और inits। लेकिन जब फ़ाइल नाम में एक स्थान होता है, तो यह कहता है कि यह अस्तित्व में नहीं है। और जब मैं if-else विधि को हटा देता हूं, तो यह init है, लेकिन क्रैश क्योंकि फ़ाइल मौजूद नहीं है। मैंने नियमित पथ के साथ फ़ाइल पथ में% 20 को प्रतिस्थापित करने का प्रयास किया है, लेकिन विधि अन्य भाग को कॉल करना जारी रखती है।
तो, फ़ाइल पथ मानकीकृत और पठनीय नहीं है, या मेरी और विधि गलत है?
आपके कोड में "% 20" और परिवर्तनीय नामकरण ("... URL") द्वारा निर्णय यह प्रतीत होता है कि आप फाइल पथों के साथ फ़ाइल यूआरएल (एन्कोड रिक्त स्थान "% 20" इत्यादि) को भ्रमित कर रहे हैं (रिक्त स्थान का उपयोग करता है, आदि)। – Regexident
फ़ाइल यूआरएल दस्तावेज़ से एक सेब विधि में एक स्ट्रिंग में परिवर्तित किया गया है उदाहरण उदाहरण। हालांकि यूआरएल एक गैर-डी नियंत्रक को पास किया जाता है। तो, मैं इसे कैसे ठीक करूं? – CodaFi