nsbundle

Load view from NIB file from several different UIViewControllers

家住魔仙堡 提交于 2020-01-01 20:03:43
问题 I have been loading view from Nib files successfully using the approach found on this site [[NSBundle mainBundle] loadNibNamed:@"YourNibName" owner:self options:nil]; The problem is that, because we have to set the File Owner, this nib file becomes "attached" to this view controller. This view is subclass of UITableViewCell and I wanted to load this nib file from several different vc's. Thanks for your help. 回答1: I'll present two options: Create a class NibLoader with a single @property

Getting iPhone mainBundle Files

China☆狼群 提交于 2020-01-01 09:13:10
问题 I dont know the exact code i need to retrieve all of the filenames of the resources in my iphone apps mainBundle. if i could have some kind of code like: NSArray *array = [[NSBundle mainBundle] getAllResourceFilenames]; it would be helpful. thanks inadvanced for any help! 回答1: You should look at the SDK documentation for NSFileManager, but this will get you started: NSString *path = [[NSBundle mainBundle] resourcePath]; NSFileManager *fm = [NSFileManager defaultManager]; NSError *error = nil;

iphone copying folder from bundle to documents

青春壹個敷衍的年華 提交于 2019-12-29 02:10:11
问题 I'm having the hardest time getting this to work. I'm trying to copy a folder from my bundle to the documents directory. the folder I'm trying to find is here: ...app/Resources/12/(a bunch of jpgs) NSString *myPath = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:@"12"]; NSLog(@"%@",myPath);/// returns "..../MyApp.app/12" NSArray *arrayOf12s = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:myPath error:nil]; NSLog(@"%@",arrayOf12s); ////always returns NULL 回答1:

Why can't code inside unit tests find bundle resources?

百般思念 提交于 2019-12-27 16:28:11
问题 Some code I am unit testing needs to load a resource file. It contains the following line: NSString *path = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"txt"]; In the app it runs just fine, but when run by the unit testing framework pathForResource: returns nil, meaning it could not locate foo.txt . I've made sure that foo.txt is included in the Copy Bundle Resources build phase of the unit test target, so why can't it find the file? 回答1: When the unit test harness runs your code,

Why can't code inside unit tests find bundle resources?

流过昼夜 提交于 2019-12-27 16:26:09
问题 Some code I am unit testing needs to load a resource file. It contains the following line: NSString *path = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"txt"]; In the app it runs just fine, but when run by the unit testing framework pathForResource: returns nil, meaning it could not locate foo.txt . I've made sure that foo.txt is included in the Copy Bundle Resources build phase of the unit test target, so why can't it find the file? 回答1: When the unit test harness runs your code,

Loading resource_bundle error in cocoapods

断了今生、忘了曾经 提交于 2019-12-25 01:28:14
问题 I am trying to make my own cocoapods, I used images. When I follow the tutorial, I get an error. .podspec s.resource_bundles = { 'SSSlidingSelector' => ['SSSlidingSelector/Assets/*.xcassets'] } Class/SlidingSelector.m - (UIImage *)getImageWithName:(NSString *)imageName { NSBundle *bundle = [NSBundle bundleForClass:[self class]]; NSURL *url = [bundle URLForResource:@"SSSlidingSelector" withExtension:@"bundle"]; NSBundle *targetBundle = [NSBundle bundleWithURL:url]; UIImage *image = [UIImage

Remap UIWebView root URL to [[NSBundle mainBundle] bundleURL]

旧街凉风 提交于 2019-12-23 15:19:38
问题 I've got some HTML and some images in my iPhone app, arranged something like: html/ foo.html images/ bar.png I can get bar.png to appear in my UIWebView a couple of different ways -- either loading foo.html from an NSUrl , and walking back up the directory tree from the html directory: <img src="../images/bar.png"/> or by loading foo.html into a string, using loadHtmlString , and using [[NSBundle mainBundle] bundleURL] as the baseURL : <img src="images/bar.png"/> Both of these are kind of

Trying to replace deprecated loadnibnamed:owner

六月ゝ 毕业季﹏ 提交于 2019-12-23 10:19:12
问题 I'm trying to replace the deprecated [NSBundle loadNibNamed:@"Subscriptions" owner:self]; with this instead (only thing I can find that's equivalent) [[NSBundle mainBundle] loadNibNamed:@"Subscriptions" owner:self topLevelObjects:nil]; but the dialog pops up and disappears right away instead of staying open like it was doing with the deprecated call. This code is inside a viewcontroller like this. - (id)init{ self = [super init]; if (self) { //[NSBundle loadNibNamed:@"Subscriptions" owner

playing mp3 from nsbundle

烈酒焚心 提交于 2019-12-23 04:07:33
问题 SETUP I put a mp3 into my bundle just for testing, i will have them download into the documents directory. But for now i am going to work off the bundle. I have found a couple tutorials, but not anything for what i need. The below is definitely a mix of a couple solutions and probably not the best approach. Problem How do i pull a song out of my bundle and play within the app? //Create an instance of MPMusicPlayerController MPMusicPlayerController* myPlayer = [MPMusicPlayerController

Can not make path to the file in Swift

亡梦爱人 提交于 2019-12-22 12:30:16
问题 I try to open the file in Swift. For it I create the file path. It doesn't work. maaaacy:~ $ pwd /Users/tsypa maaaacy:~ $ cat a.txt test maaaacy:~ $ ./a.swift nil! maaaacy:~ $ The script: #!/usr/bin/xcrun swift import Foundation var filePath = NSBundle.mainBundle().pathForResource("a", ofType: "txt", inDirectory: "/Users/tsypa") if let file = filePath { println("file path \(file)") // reading content of the file will be here } else { println("nil!") } What's wrong? 回答1: When using Swift REPL,