I have set up a splash screen for my app project and would like to have an sound (mp3) play just after the splash screen loads. I am new to using xcode and wondered whether some one could advise on what code I will need to input/where to input it..
Many Thanks
You implement a yourintrosound.wav system sound in the first view controller, then play it with the appDelegate just after the view controller is loaded:
in your firstViewController.h
#interface...
CFURLRef yourSound;
SystemSoundID soundFileObject;
#property (readwrite) CFURLRef yourSound;
#property SystemSoundID soundFileObject;
in your firstViewController.m viewDidLoad
NSURL *rightSound = [[NSBundle mainBundle] URLForResource: #"yourintrosound" withExtension: #"wav"];
self.yourSound = (CFURLRef) [rightSound retain];
AudioServicesCreateSystemSoundID (yourSound, &soundFileObject);
[rightSound release];
in your AppDelegate.m application: didFinishLaunchingWithOptions:
(just after [window makeKeyAndVisible] or any splash screen display you implemented)
AudioServicesPlaySystemSound (firstViewController.soundFileObject);
and do dot forget the AudioToolbox framework!
Related
The related code below worked perfect when i was building for iOS 7, but it seems now in iOS 8, it's not working properly.
By properly, I mean in the sense where it's not actually sending the file or whatever to the chosen app.
Example: If I selected Mail, it would open the mail app with the image or zip I chose in the text field. Now it won't send and it takes forever to call/dismiss the UIDocumentInteractionController.
What am I doing wrong?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
NSString *fileName = [directoryContents objectAtIndex:indexPath.row];
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:#"Downloads"];
path = [path stringByAppendingPathComponent:fileName];
documentController = [[UIDocumentInteractionController alloc] init];
documentController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
[documentController setDelegate:self];
[documentController presentOptionsMenuFromRect:CGRectZero inView:self.view animated:YES];
[documentController retain];
}
I have been playing around with the UIDocumentInteractionController and Delegate trying to fix a similar problem, the controller opened-up alright but selecting an application caused it to close without doing anything, my delegate method documentInteractionControllerDidDismissOpenInMenu also run alright afterwards.
In the console i got the notification enabledRemoteNotificationTypes is not supported in iOS 8.0 and later.
It turns out that this problem will accrue when one of these delegate methods is called :
documentInteractionControllerDidDismissOpenInMenu
documentInteractionControllerDidDismissOptionsMenu
(and possibly others, i did not check all of them)
I did not find any comment in the IOS Development Library or the UIDocumentInteractionController.h about these methods not supported for IOS 8.1 but at this point i cant find any other explanation.
Solution :
i replaced documentInteractionControllerDidDismissOpenInMenu
with didEndSendingToApplication
and it solved the problem for me.
Hello guy's and girl's,
I got a question, i'm new to objective c and iphone apps. But i'm trying to make a few simple applications but i have trouble with creating a segue that also sets the label in the next view controller.
The situation is as following. i have a Tableviewcontroller with an loaded nsarray of data.
Next i have created a segue (ctrl + drag). Al works so far.
Now the viewcontroller has an label, i have namend the segue and a'm trying the following code.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"ShowTitleInOtherViewController"]) {
PracticeViewController *pvc = [segue destinationViewController];
pvc.labelForDisplayData.text = #"Segue complete";
pvc.labelForDisplayData.textColor = [UIColor blueColor];
pvc.labelForDisplayData.font = [UIFont boldSystemFontOfSize:50];
}
}
i have imported the header and the viewcontroller header looks like the following:
#interface PracticeViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *labelForDisplayData;
#end
Please tell me what i am doing wrong. (there are no error's)
Recommendation
From your description (as long as you've connected the outlet in your storyboard) then this workflow should be okay. You are not showing how the segue is initialized (i.e., performSegueWithIdentifier). Please see this stack overflow question for more details (link). I've posted a few tips on manual segueing. If you've resolved this issue please update your original question. Here is another sample of calling a manual segue (link). Please advise if this issue is still open or share the problem/solution.
New Apple Tutorial on Storyboards
Hope this helps.
Make the Label property to strong instead of weak
#interface PracticeViewController : UIViewController
#property (strong, nonatomic) IBOutlet UILabel *labelForDisplayData;
#end
I am making a splitview application for ipad and I need to display a different view controller for login purposes.
I call this in the didFinishLaunchingWithOptions function in Appdelegate:
LoginViewController *login = [[LoginViewController alloc] init];
[info setModalTransitionStyle: UIModalTransitionStyleCrossDissolve];
[self presentViewController:login animated:YES completion: nil];
but I get the error "No visible #interface for AppDelegate declares the selector presentViewController" on the third line.
The view controller I want to display is set to the LoginViewController class.
I have Imported all classes.
I am pretty new to programming and would really appreciate any help!
Thanks!!
What the error message says is that the class AppDelegate does not contain a method called presentViewController. Indeed, that method belongs to UIViewController class.
What you should do depends on how you created your project, whether it uses a navigation controller, a tab bar controller, or a simple view controller.
From your comment, I understand you used the Window-based template (or Empty application) to create your project. In this case, in your application:didFinishLaunching: you should have something like this:
self.login = [[LoginViewController alloc] init];
[self.window addSubview:self.login.view];
and also add to your AppDelegate.h the following declaration:
#property (nonatomic, strong) LoginViewController* login;
If this seems not to apply to your case, please, post your definition of application:didFinishLaunching:
I am totally new at this, but here goes:
I want to press a button in my application, and have an image display (I am planning to read it off of a camera, but to start with, I will open a .TIF file.) However, within the interface builder, I can make buttons within an NSObject object, but the literature makes it sound like I need to make an NSView object to display a file. The problem is, when I do this, the NSObject object does not seem to talk to the NSView object. I am trying to do something like:
NSString *inFilePath;
inFilePath = #"/Volumes/Data/Temp/Smiles.tiff";
NSImage *TestImage = [[NSImage alloc] initWithContentsOfFile:inFilePath];
[MyView setImage:TestImage];
Here, MyView is the NSView object. I get warnings that MyView may not respond to setImage. I have tried to define an IBOutlet within the NSObject object, and although I can connect it within the interface builder, console gives me the error:
unrecognized selector sent to class 0x1e080
So, it's not clear what the next step is. Is there an easy way to get two different objects to "talk to" each other?
Thanks
You want an NSImageView object. In the Interface Builder library this is called an Image Well, but you can configure it so that it doesn't have a bezel.
NSImageView is a subclass of NSView that is optimised for displaying images.
In your header (.h) file, you should have something like this:
#interface MyController : NSObject
{
//this declares an outlet so you can hook up the
//image view in Interface Builder
IBOutlet NSImageView* imageView;
}
#end
And in your implementation (.m) file:
#implementation MyController
//called once the nib is loaded and all outlets are available
- (void)awakeFromNib
{
NSString *inFilePath = #"/Volumes/Data/Temp/Smiles.tiff";
NSImage *testImage = [[NSImage alloc] initWithContentsOfFile:inFilePath];
#if !__has_feature(objc_arc)
[testImage autorelease];
#endif
//imageView is your outlet
[imageView setImage:testImage];
}
#end
In Interface Builder you should hook up the imageView outlet of your class to point to the NSImageView you placed on your view.
Hi I have a splitview app that is working fine until I add a TabBar in the rootview section. The problem is that when I add the TabBar to the rootview the app does not rotate to landscape, if I change the orientation the view remains in portrait mode.
How can I solve this?. Hope you can help
#import "SplitViewTest3AppDelegate.h"
#import "SISACWelcomeViewController.h"
#implementation SplitViewTest3AppDelegate
#synthesize window, masterViewController, splitViewController,masterViewTabBarController, searchViewController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
masterViewController = [[MasterViewController alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
masterNavigationController.tabBarItem.image = [UIImage imageNamed:#"Folder.png"];
//NewsFeedsNavigationController *newsFeedsNavigationController = [[NewsFeedsNavigationController alloc] init];
SISACWelcomeViewController *sisacWelcomeViewController = [[SISACWelcomeViewController alloc] init];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:sisacWelcomeViewController];
searchViewController = [[UIViewController alloc] initWithNibName:#"SearchView" bundle:nil];
searchViewController.tabBarItem.image = [UIImage imageNamed:#"Search-icon.png"];
masterViewTabBarController = [[UITabBarController alloc] init];
masterViewTabBarController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, searchViewController, nil];
masterViewController.detailNavigationController = detailNavigationController;
splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:masterViewTabBarController, detailNavigationController, nil];
splitViewController.delegate = sisacWelcomeViewController;
// Add the split view controller's view to the window and display.
[window addSubview:splitViewController.view];
//[masterNavigationController.view addSubview:tab.view];
[window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
/*
Restart any tasks that were paused (or not yet started) while the application was inactive.
*/
}
- (void)applicationWillTerminate:(UIApplication *)application {
/*
Called when the application is about to terminate.
*/
}
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
*/
}
- (void)dealloc {
[window release];
//[tab release];
[super dealloc];
}
#end
The answer below is correct. If you are adding tabs which include using the CoreDataTableView controller (that is used with the CS193P course), be sure to add a method to allow for any orientation. If not, your split view will not work correctly.
SOLVED:
I had the same issue.
Without the TabBar all is well, add the TabBar and the rotation breaks.
I guessed that there is something broken in the responder chain or view hierarchy.
So I was about to submit as a bug. So wrote a test app to demo to Apple (because they ALWAYS ask for one), and it worked. Hooray, but why?
These are my findings from the Apple docs.
From the View Programming Guide for iOS.
Split View Controller
"A split view controller must always be the root of any interface you create."
Thus they should not be embedded within a TabBar View, although I understand that there is a workaround out in the wild.
Also:
Creating a Tab Bar Interface
"Install it as one of the two root views in a split view interface. (iPad only)"
Solution:
After much more investigation, and some trial and error, I found the issue.
Of course it seems so obvious NOW.
When the SplitView tests for shouldAutorotateToInterfaceOrientation, it tests every possible view on the whole hierarchy, that is EVERY view in the MasterView, thus EVERY view in the TabBar, and EVERY view in the DetailView, thus EVERY view in the current NavigationStack.
The fly in the ointment is that a newly created ViewController does not support Landscape by default.
Where I had gone wrong was: I had created ALL of the TabBar subviews, but not written any more code yet, because I wanted to get the SplitView with TabBar working first, thus 1 of my Tab Views had not been changed from the default.