Navigation Bar missing in iphone - iphone

I am very new to iPhone development, but I have been given an iPhone application to debug and I don't know where to start.
The problem is as follows:
The app has a view which has a navigation bar on top. When I press the home button on the device, the application goes to suspended mode I suppose. When I go back to the app from the list I can see the view but without navigation bar. Why would the navigation bar disappear, and how can I fix it?
Here is the code for the same
-(void)viewWillAppear:(BOOL)animated
{
[self prepareNavBar];
}
-(void)prepareNavBar
{
self.navigationItem.hidesBackButton = NO;
CustomNavBar *the_pNavBar = [[CustomNavBar alloc] init];
[the_pNavBar prepareNavbarWithLeftButtonImage:nil leftButtonAction:nil titleImage: [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"ip4_heading_comments.png"]] rightButtonImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"ip4_submit.png"]] rightAction:#selector(postComment) target:self backgroundImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"ip4_background_grey_150px.png"]] navigationBar:self.navigationController.navigationBar isStandardNavBar:NO];
[the_pNavBar release];
}
please let me know if any other code is required

I fixed the issue by the following code
-(void)didBecomeActive:(NSNotificationCenter *)in_pNotif
{
[self performSelector:#selector(test) withObject:nil afterDelay:0.01];
}
-(void)test
{
self.navigationController.toolbarHidden = YES;
}

Related

iPhone Creating a Modal Movie Window

I have created an app that incorporates a table view, detail view, and a web view. I have established a cell in the table view that takes a URL from an RSS feed and will display it in a webview. The URL is an .MP4 file which causes the video to play. The problem I am having is that when the video ends, I cannot go back to the previous screen. The code is below:
DetailViewController.m load webview
if (indexPath.section == SectionHeader && indexPath.row == SectionHeaderEnclosure) {
if (item.enclosures) {
for (NSDictionary *dict in item.enclosures){
NSString *url = [dict objectForKey:#"url"];
NSLog(#" url is : %#",url);
//EXPERIMENTAL
WebViewController *webVC = [[WebViewController alloc] initWithURL:url];
[self presentModalViewController:webVC animated:YES];
}
}
}
WebViewController.m
- (void)loadView
{
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
self.view = webView;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_url]]];
}
//Dismiss modal view
- (IBAction) done:(id)sender {
NSLog(#"done:");
[self dismissModalViewControllerAnimated:YES];
}
I think it would be better to use an MPMoviePlayerViewController. The documentation shows how to set it up with the URL directly using initWithContentURL: and present it modally. You can listen for notifications thet the movie has ended and dismiss it when done. Lots of good stuff in the documentation.

iPhone App Crashes due to Low Memory but works fine in simulator

Dear all, I have a navigation-based app with about 60 views.
I have run with the following :
1. Build and analyse : bulid is successful with no complains.
2. Instruments allocation and leaks : no leaks.
However, the app crashed in iPhone or iPad but works fine in simulator.
The crash occurs at around 50th view.
There is no crash reports but I do see LowMemory.log in the crashreporter folder.
I have upgraded my iphone and ipad to 4.2
Does anyone have ideas what could be wrong?
I have been reading and troubleshooting for a week.
Thank you for all the replies.
My app has a root view called contentViewController and users can navigate to 4 quizzes from here.
This is the code I use to return to my root view.
- (void)goHome {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Warning"
message: #"Proceed?"
delegate: self
cancelButtonTitle:#"Yes"
otherButtonTitles:#"No",nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
[[self navigationController] setNavigationBarHidden:NO animated:YES];
if (buttonIndex == 0) {
NSArray * subviews = [self.view subviews];
[subviews makeObjectsPerformSelector:#selector(removeFromSuperview)];
self.view = nil;
if (self.contentViewController == nil)
{
ContentViewController *aViewController = [[ContentViewController alloc]
initWithNibName:#"ContentViewController" bundle:[NSBundle mainBundle]];
self.contentViewController = aViewController;
[aViewController release];
}
[self.navigationController pushViewController:self.contentViewController animated:YES];
}
}
Sample code for pushing views :
-(IBAction) buttonArrowClicked:(id)sender {
NSURL *tapSound = [[NSBundle mainBundle] URLForResource: #"click"
withExtension: #"aif"];
// Store the URL as a CFURLRef instance
self.soundFileURLRef = (CFURLRef) [tapSound retain];
// Create a system sound object representing the sound file.
AudioServicesCreateSystemSoundID (
soundFileURLRef,
&soundFileObject
);
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![[defaults stringForKey:#"sound"] isEqualToString:#"NO"]) {
AudioServicesPlaySystemSound (soundFileObject);
}
if (self.exercise2ViewController == nil)
{
Exercise2ViewController *aViewController = [[Exercise2ViewController alloc]
initWithNibName:#"Exercise2ViewController" bundle:[NSBundle mainBundle]];
self.exercise2ViewController = aViewController;
[aViewController release];
}
[self.navigationController pushViewController:self.exercise2ViewController animated:YES];
}
You will normally not run into memory problems when running under the simulator, so these errors are not automatically encountered on this platform.
The simulator does however have a feature where you can manually trigger a Low Memory event. If this is actually the cause of the crash on the device, then it might also be possible that you can trigger the same bug in the simulator in this way.
Sharing some code about how you push the view controllers will allow others to help you with this.
You can pop to root view controller more easily by doing:
[self.navigationController popToRootViewControllerAnimated:YES];
You are actually pushing a new instance of your root view controller in the code that you have shared.

UIWebView gets cleared after dismissing a fullscreen modal

I have a UIWebView which loads a html string on viewDidLoad. It detects if the user clicks a link and display a modal view, but when i close the modal view the UIWebView's html has gone! If i use a FormSheet Modal Style the content stays behind, its only fullscreen modals that cause this. Obviously i can just input the html string again on viewWillAppear which fixes it but this causes makes the content flick back on which i don't want. heres my code:
-(void)viewDidLoad {
[self loadArticleText];
...
}
-(void)loadArticleText {
NSString *htmlHead = #"<html><head>...";
NSString *htmlFoot = #"</body></html>";
NSString *htmlContent = [self.articleData valueForKey:#"fulltext"];
NSString *html = [[NSString alloc] initWithFormat:#"%#%#%#", htmlHead, htmlContent, htmlFoot];
[self.articleView loadHTMLString:html baseURL:nil];
[html release];
}
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSURL *URL = [request URL];
ImageViewer *imageView = [[[ImageViewer alloc] initWithNibName:#"ImageViewer" bundle:nil] autorelease];
imageView.imageURL = URL;
[self presentModalViewController:imageView animated:YES];
return NO;
} else {
return YES;
}
}
If i change 'return NO;' to 'return YES;' the webView contents stays, like it should, but obviously it loads the image.
Any help??
Thanks
[self presentModalViewController:ImageView animated:YES];
It looks like you are making a class call rather than an instance call on ImageView.

how to play different audio files with same media player in a separate view- iphone sdk?

I've been trying and researching for countless hours but for some reason I just cant get my head around it and I know its a simple answer. Please Help!
I have a view with different buttons, -(ScrollViewController1)
the different buttons push in one view, -(b1ViewController)
this view contains the media player,
In a nutshell, I cant figure out how to get the media player to play a different audio file depending on which button in the first view was pressed.
I'm trying not to make a different view with a different media player for every button.
Could someone demonstrate it please so that I can understand it? Thanks a million.
Heres the relevant code-
(ps- theres a reason for the tags, I didnt want to get too much into for the sake of asking a clear question and keeping it straight forward.)
#implementation ScrollViewController1
- (IBAction)pressedb1view {
if (thebutton.tag==101) {
[self performSelector:#selector(dismissb1pop:) withObject:nil afterDelay:0.1];
b1view.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:b1view animated:YES];
}
if (thebutton.tag==102) {
[self performSelector:#selector(dismissb1pop:) withObject:nil afterDelay:0.1];
b1view.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:b1view animated:YES];
}
if (thebutton.tag==103) {
[self performSelector:#selector(dismissb1pop:) withObject:nil afterDelay:0.1];
b1view.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:b1view animated:YES];
}
}
etc, etc, etc....
in the next view which contains the mediaplayer I have-
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#interface b1ViewController : UIViewController {
MPMoviePlayerController *moviePlayer;
NSURL *movieURL;
}
in the .m -
-(void)viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:NO animated:YES];
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"music1" ofType:#"mp3"];
NSURL *url = [NSURL fileURLWithPath:urlStr];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(0, 0, 320, 40);
[moviePlayer play];
}
EDIT:
Im passing text from the first view to a uilabel on the second view using the following in the first view-
[b1view changeSiteText:#"im stuck here"];
in the second view Im doing this in the .h-
- (IBAction) changeSiteText:(NSString *)str;
and in the .m im doing this-
- (IBAction) changeSiteText:(NSString *)str{
lblSiteTxt.text = str;
}
Is there a way to implement a similar method for the mediaplayer,??? maybe doing
something like
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"%#" ofType:#"mp3", str];
Im stuck!!
Help!
Do you push the view or present it?
Add a method in the player class which when passed various arguments it plays the appropriate track or whatever. Then the different IBActions will invoke this method.

How to change a new nib when I rotate the device?

I have a helloController which is a UIViewController, if I rotate the device, I want it change it to load a new nib "helloHorizontal.xib", how can I do? thank you.
You could you something like this, (I dont have xcode handy so this code might not be completely accurate)
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)){
WhatYourNewViewClassISCAlled* newView = [[WhatYourNewViewClassISCAlled alloc] initWithNibName:#"NIBNAME" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:newView animated:YES];
}
This is the correct way, I believe. I'm using it in my apps and it works perfectly
triggers on WILL rotate, not SHOULD rotate (waits until the rotate anim is about to start)
uses the Apple naming convention for landscape/portrait files (Default.png is Default-landscape.png if you want Apple to auto-load a landscape version)
reloads the new NIB
which resets the self.view - this will AUTOMATICALLY update the display
and then it calls viewDidLoad (Apple will NOT call this for you, if you manually reload a NIB)
(NB stackoverflow.com requires this sentence here - there's a bug in the code formatter)
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation) )
{
[[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:#"%#-landscape", NSStringFromClass([self class])] owner:self options:nil];
[self viewDidLoad];
}
else
{
[[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:#"%#", NSStringFromClass([self class])] owner:self options:nil];
[self viewDidLoad];
}
}