AppDelegate Navigation error - iphone

- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSError *error = nil;
NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:#"username"];
NSString *str = [SFHFKeychainUtils getPasswordForUsername:username andServiceName:#"mybibleapp" error:&error];
NSLog(#"previous un");
NSLog(#"%#", str);
if(str != nil)
{
main_page *detailViewController = [[main_page alloc] initWithNibName:#"main_page" bundle:nil];
// Pass the selected object to the new view controller.
// detailViewController.localStringtextnote = localStringtextnote;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
When I put this code for navigating to main_page it shows an error that property navigationController not found on object of appdelegate so i put this code insted of the above
main_page *log = [[main_page alloc] initWithNibName:#"main_page" bundle:nil];
[window addSubview:tabController.view];
[window addSubview:log.view];
[window makeKeyAndVisible];
the page is redirected to main_page but nothing is working in this way. no navigation in main_page is working, I cant redirect any page from the main_page. So what can I do to solve these errors.

You can create a "proxy" viewController without nib which is loaded in MainWindow's navigationController and then do something like the following, in the proxy's viewDidLoad
NSError *error = nil;
NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:#"username"];
NSString *str = [SFHFKeychainUtils getPasswordForUsername:username andServiceName:#"mybibleapp" error:&error];
NSLog(#"previous un");
NSLog(#"%#", str);
UIViewController *controller;
if (!error && nil != str) {
controller = [[DetailViewController alloc] init];
} else {
controller = [[LoginViewController alloc] init];
}
[[self navigationController] pushViewController:controller animated:YES];
[controller release];

Initial page loading is usually handled in the MainWindow.xib nib. You shouldn't have to manually load it.
Try creating a new project from a template and then do in and look at how the appDelegate and MainWindow.xib are setup.

Related

How to show a UIViewController on the First time Application Launch?

I want to know how to show a page on the very first time launch of the application,I had serch for these and get many code but in my case its not working for me, I have this code in DidFinishLaunching Method,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],#"firstLaunch",nil]];
//If First Launch
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"firstLaunch"]) {
//Show help view
UIScrollView_PagingViewController *detailViewController = [[UIScrollView_PagingViewController alloc] initWithNibName:#"UIScrollView_PagingViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
else {
NSError *error = nil;
NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:#"username"];
NSString *str = [SFHFKeychainUtils getPasswordForUsername:username andServiceName:#"mybibleapp" error:&error];
NSLog(#"previous user");
NSLog(#"%#", str);
if (!error && nil != str)
{
ParallelReadViewController *detailViewController = [[ParallelReadViewController alloc] initWithNibName:#"ParallelReadViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
else
{
RootViewController *detailViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
}
but when i run this code ,it shows a blank white screen ,nothing shows.
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],#"firstLaunch",nil]];
//If First Launch
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"firstLaunch"]) {
//Show help view
UIScrollView_PagingViewController *detailViewController = [[UIScrollView_PagingViewController alloc] initWithNibName:#"UIScrollView_PagingViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
else {
i put the above code for launch UIScrollView_PagingViewController to launch .but no luck.What is the mistake i made in the above code.?.please help me.
Thanks in advance.
You are trying to push that controller at very first time but at the roo there is no any controller. so you have to add in window first. then you can push the UIViewController
self.window.rootViewController = detailViewController.view;
don't release the viewController before use.
You are not placing the code in right place. Don’t put this code in AppDelegate try to keep your appdelegate as clean as possible for better #performance. Use some ViewController which will get call after splash screen and check if your code works there.
try this
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"firstLaunch"])
{
UIScrollView_PagingViewController *detailViewController =[[UIScrollView_PagingViewController alloc] initWithNibName:#"UIScrollView_PagingViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
self.navController=[[UINavigationController alloc] initWithRootViewController:detailViewController];
self.window.rootViewController=self.navController;
}
Just do a trcik,
Don’t put this code in AppDelegate try to keep your appdelegate as clean as possible for better performance.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
}
And Place this Code in you RootViewController
Everytime when the application will get launch, it check the condition in delegate method, instead will check in RootViewController.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],#"firstLaunch",nil]];
//If First Launch
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"firstLaunch"]) {
//Show help view
UIScrollView_PagingViewController *detailViewController = [[UIScrollView_PagingViewController alloc] initWithNibName:#"UIScrollView_PagingViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:NO];
[detailViewController release];
}
else {
NSError *error = nil;
NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:#"username"];
NSString *str = [SFHFKeychainUtils getPasswordForUsername:username andServiceName:#"mybibleapp" error:&error];
NSLog(#"previous user");
NSLog(#"%#", str);
if (!error && nil != str)
{
ParallelReadViewController *detailViewController = [[ParallelReadViewController alloc] initWithNibName:#"ParallelReadViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:NO];
[detailViewController release];
}
else
{
// RootViewController *detailViewController = [[RootViewController alloc] //initWithNibName:#"RootViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
// [self.navigationController pushViewController:detailViewController //animated:NO];
//[detailViewController release];
}
}

iPhone -trouble with a loading data from webservice into a tableview

I am using a Window based application and then loading up my initial navigationview based controller in the appDelegate part - application didFinishLaunchingwithOptions (UPDATED)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
The method of getting the data from the webservice is usually triggered in this method of viewdidload .... in the [self getData]; method.
- (void)viewDidLoad
{
[super viewDidLoad];
if (_refreshHeaderView == nil) {
EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, self.view.frame.size.width, self.tableView.bounds.size.height)];
view.delegate = self;
[self.tableView addSubview:view];
_refreshHeaderView = view;
[view release];
}
// update the last update date
[_refreshHeaderView refreshLastUpdatedDate];
[self loadImages];
HUDMB = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUDMB];
HUDMB.dimBackground = YES;
// Regiser for HUD callbacks so we can remove it from the window at the right time
HUDMB.delegate = self;
HUDMB.labelText = #"Loading..";
[HUDMB show:TRUE];
[self getData];
[self.tableView reloadData];
}
Before loading it if the user is not registered/ does not have a credentials present then it takes the user to a login view controller .
- (void)loadView {
[super loadView];
if([Preferences isValid]?YES:NO)
{
}
else
{
int r = arc4random() % 5;
switch (r) {
case 0:
{
loginViewController *sampleView = [[loginViewController alloc] initWithNibName:#"loginViewController" bundle:nil];
[self.navigationController presentModalViewController:sampleView animated:YES];
[sampleView release];
}
break;
case 1:
{
loginViewController *sampleView = [[loginViewController alloc] initWithNibName:#"loginViewController" bundle:nil];
[sampleView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self.navigationController presentModalViewController:sampleView animated:YES];
[sampleView release];
}
break;
case 2:
{
loginViewController *sampleView = [[loginViewController alloc] initWithNibName:#"loginViewController" bundle:nil];
[sampleView setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self.navigationController presentModalViewController:sampleView animated:YES];
[sampleView release];
}
break;
case 4:
{
loginViewController *sampleView = [[loginViewController alloc] initWithNibName:#"loginViewController" bundle:nil];
[sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self.navigationController presentModalViewController:sampleView animated:YES];
[sampleView release];
}
break;
case 3:
{
loginViewController *sampleView = [[loginViewController alloc] initWithNibName:#"loginViewController" bundle:nil];
[sampleView setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self.navigationController presentModalViewController:sampleView animated:YES];
[sampleView release];
}
break;
default:
break;
}
}
}
I think the getdata function is making a lot of troubles. so let me add that and also the corresponding functions i use for data retrieval and serialization.
-(void)getData{
NSLog(#"loggin into call sheet page");
[self getCallSheetData];
NSLog(#"after call sheet");
}
- (void)getCallSheetData
{
NSString *postCMD = #"Blah... Blah... Blah...";
NSMutableData *postDataCMD = (NSMutableData *)[postCMD dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSURL *url = [NSURL URLWithString:[Preferences getURL]];
// NSLog(#"get call Sheet");
NSString *postLengthCMD = [NSString stringWithFormat:#"%d", [postDataCMD length]+1];
// NSLog(#"The CS String: %#",[Preferences retriveSession]);
requestCMD = [ASIHTTPRequest requestWithURL:url];
[requestCMD setURL:url];
[requestCMD addRequestHeader:#"Content-Length" value:postLengthCMD];
[requestCMD addRequestHeader:#"Content-Type" value:#"application/x-www-form-urlencoded"];
[requestCMD addRequestHeader:#"user-Agent" value:#"Mobile 1.4" ];
[requestCMD addRequestHeader:#"Content-Language" value:#"en-US"];
[requestCMD addRequestHeader:#"Accept-Encoding" value:#"gzip"];
[requestCMD addRequestHeader:#"Cookie" value:[Preferences retriveSession]];
[requestCMD setPostBody:postDataCMD];
[requestCMD setDelegate:self];
[requestCMD startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSMutableArray *CSArray = [[NSMutableArray alloc] init];
if( [[request responseString] isEqualToString:#"OK"]){
return;
}
// Use when fetching binary data
NSData *responseData = [request responseData];
NSDateFormatter *formatter1=[[NSDateFormatter alloc]init];
[formatter1 setDateFormat:#"yyyy-MM-dd'T'HH:mm:ss'Z'"];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:#"GMT"];
[formatter1 setTimeZone:gmt];
NSDateFormatter *formatterFinal=[[NSDateFormatter alloc]init];
[formatterFinal setDateStyle:NSDateFormatterMediumStyle];
[formatterFinal setTimeStyle: NSDateFormatterShortStyle];
[formatterFinal setLocale:[NSLocale currentLocale]];
JSONDecoder *jCSArray = [[JSONDecoder alloc]init];
NSMutableArray *theObject = [jCSArray objectWithData:responseData];
// CallSheet= [NSMutableArray arrayWithCapacity:50];
for(id key in theObject)
{
csr = [[CallSheetRecord alloc] init];
// cName,cCompany,cId,cMemberId,crcStatus,crcTarget,cImportance,cLastContact
csr.importance = #"1";
csr.rcstatus = #"1";
csr.rcTarget = #"1";
csr.company = #"";
csr.lastContact= #"";
if([key valueForKey:#"firstName"] != Nil)
{
csr.name = [NSString stringWithFormat:#"%#",[key valueForKey:#"firstName"]] ;
if ([key valueForKey:#"lastName"] != Nil) {
csr.name = [csr.name stringByAppendingString:#" "];
csr.name = [csr.name stringByAppendingString:[NSString stringWithFormat:#"%#",[key valueForKey:#"lastName"]]];
}
}
if([key valueForKey:#"company"] != Nil)
{
csr.company = [NSString stringWithFormat:#"%#",[key valueForKey:#"company"]] ;
}
if([key valueForKey:#"memberId"] != Nil)
{
csr.memberId = [NSString stringWithFormat:#"%#",[key valueForKey:#"memberId"]] ;
}
if([key valueForKey:#"id"] != Nil)
{
csr.id_ = [NSString stringWithFormat:#"%#",[key valueForKey:#"id"]] ;
}
if([key valueForKey:#"lastContact"] != Nil)
{
NSDate *finalDate =[formatter1 dateFromString:[NSString stringWithFormat:#"%#",[key valueForKey:#"lastContact"]]];
//NSString *timeStamp = [formatter1 stringFromDate:[finalDate descriptionWithLocale:[NSLocale currentLocale]]];
//NSLog(#"Time stamp : %#",[finalDate descriptionWithLocale:[NSLocale currentLocale]]);
//NSLog(#"Time stamp : %#",timeStamp);
//csr.lastContact = [key valueForKey:#"lastContact"];
csr.lastContact = [formatterFinal stringFromDate:finalDate];
}
if([key valueForKey:#"importance"] != Nil)
{
csr.importance = [NSString stringWithFormat:#"%#",[key valueForKey:#"importance"]];
}
if([key valueForKey:#"rcStatus"] != Nil)
{
csr.rcstatus= [NSString stringWithFormat:#"%#",[key valueForKey:#"rcStatus"]] ;
}
if([key valueForKey:#"rcTarget"] != Nil)
{
csr.rcTarget = [NSString stringWithFormat:#"%#",[key valueForKey:#"rcTarget"]] ;
}
[CSArray addObject:csr];
}
CSD = [CSArray mutableCopy];
[CSArray release];
[formatter1 release];
[formatterFinal release];
//CallSheetArray = [CSArray mutableCopy];
//[csr release];
[jCSArray release];
[HUDMB hide:TRUE];
[self.tableView reloadData];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
UIAlertView *message = [[[UIAlertView alloc] initWithTitle:#"Hello World!"
message:[NSString stringWithFormat:#"%#",error]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]autorelease];
[message show];
}
then right after that i try to load the table with [self getData]; that i get make using webservice call using asiHTTP .. for this question lets say it takes 3 seconds time to get the data and then deserialize it . now... my question is it works out okey in the later runs as I store the username and password in a seure location... but in the first instance.... i am not able to get the data to laod to the tableview... I have tried a lot of things...
1. Initially the data fetch methods was in a diffrent methods.. so i thought that might be the problem as then moved it the same place as the tbleviewController(navigationController)
2. I event put in the Reload data at the end of the functionality for the data parsing and deserialization... nothing happens.
3. The screen is black screen with nothing displayed on it for a good 5 seconds in the consecutive launches of the app.... so could we have something like a MBPorgressHUD implemented for the same.
could any one please help for these scenarios and guidance as to what paths to take from here. ...
Update:
Bounty Just answer 2 of the questions the best you can... The property was a thing i tried but it did not work... but my problem is not that... my problem is my screen is not able to load data from a webservice after i login until i do the "pull to refresh". Next eventualy starting my app takes about 5 seconds to show the screen(till that it shows a black screen)... what is the best way to show the apps Blank screen to the End- user when they make it to the app. I dont want the user to think the app is not working or has adversly affected their phone.
There are a number of potential issues here. The first is related to [self getData] - is this blocking or not?
1. getData is blocking (synchronous)
If this method is blocking (i.e. does not return immediately) then this will explain why you are not seeing anything on the screen for a few seconds. You are currently calling this method in the main thread, so it will stop the UI from being updated until is complete.
You can make it run in the background by doing this:
- (void) getDataInBackgroundThread
{
NSAutoReleasePool *pool = [[NSAutoReleasePool alloc] init];
[self getData];
// force the table to redraw - UI operations must be on the main thread
[tableView performSelectorOnMainThread:#selector( reloadData )];
[pool drain];
}
In your main code, now instead of calling [self getData] call [self getDataInBackgroundThread];
2. getData is not blocking (asynchronous)
Even if getData is blocking, if it runs in the main thread it will still cause the UI to hang. Also, if it uses a lot of processor time it will slow down the UI and give the appearance of not running in the background.
To address this issue, you would need make sure the lengthy operation of getData really is not running in the main thread and also put in sleep() calls every so often to give some time for the UI to update.
You still haven't given enough info for people to really help, we're just guessing.
It is highly likely the delay is caused by getData. Try commenting that out or bracket it with NSLog statements to verify.
You should show us more code, specifically what is happening in getData and any delegate or notification handling implementations related to loading data.
You don't need to explicitly call [tableView reloadData] in viewDidLoad. The tableView automatically loads data the first time it is displayed.
As #dmatt said, if you are loading data asynchronously then getData would return immediately with no delay. You would typically would either respond to delegate messages or notifications (depending on how you are loading data) to reload the table when the data is finished loading and serializing.
There are lots of folks on SO who are happy to try and help you if given enough info. Especially when you offer a bounty.

UIDocumentInteractionController presentPreviewAnimated: returning NO and not showing preview

I've tried everything I can think of and it still responds NO and Apple's doesn't have any hints.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(#"finished!");
NSString *tempString = [NSString stringWithFormat:#"file://%#%#", NSTemporaryDirectory(), [[NSProcessInfo processInfo] globallyUniqueString]];
NSURL *tempURL = [NSURL URLWithString:tempString];
[receivedData writeToURL:tempURL atomically:YES];
NSLog(#"tempURL is written!");
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:tempURL];
interactionController.delegate = self;
[interactionController retain];
NSLog(#"--- %i", [interactionController presentPreviewAnimated:YES]);
NSLog(#"presented preview");
[connection release];
[receivedData release];
}
- (UIViewController*)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
NSLog(#"asdf");
UIViewController *viewController = [[[UIViewController alloc] init] autorelease];
[self.navigationController pushViewController:viewController animated:YES];
return viewController;
}
1) are you confident the document you're opening is kosher? If not, then returning NO would be the thing to expect
2) I'm puzzled by your delegate method. The present method is happy to do the pushing onto the navigation controller all by itself. Do you fair any better if you use this code instead? (See the docs for rationale.)
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller
{
return [self navigationController];
}
I had a similar issue with presentPreviewAnimated which returned NO. In my case I was missing an extension of the file. When I renamed my file from document to document.xlsx it was opened successfully.

How to push a new view upon opening push notification while app is closed?

So what I'm trying to do is when you click view on receiving a push notification when the app opens it has the presented view push a new controller with details regarding the notification. I'm using a UITabBarController with UINavigationControllers. Any help would be much appreciated, I've tried searching but I couldn't seem to find anything that pointed me in the right direction. Current code below:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
[application setStatusBarStyle:UIStatusBarStyleBlackOpaque];
tabBarController = [[UITabBarController alloc] init];
controller = [[controller alloc] init];
UINavigationController *controller1 = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
controller1.tabBarItem.image = [UIImage imageNamed:#"icon_news.png"];
[controller setTitle:#"View"];
[controller release];
controller = [[controller alloc] init];
UINavigationController *controller2 = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
controller2.tabBarItem.image = [UIImage imageNamed:#"icon_news.png"];
[controller setTitle:#"View"];
[controller release];
controller = [[controller alloc] init];
UINavigationController *controller3 = [[[UINavigationController alloc] initWithRootViewController:controller3] autorelease];
controller3.tabBarItem.image = [UIImage imageNamed:#"icon_news.png"];
[controller setTitle:#"View"];
[controller release];
controller = [[controller alloc] init];
UINavigationController *controller4 = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
controller4.tabBarItem.image = [UIImage imageNamed:#"icon_news.png"];
[controller setTitle:#"View"];
[controller release];
controller = [[controller alloc] init];
UINavigationController *controller5 = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
controller5.tabBarItem.image = [UIImage imageNamed:#"icon_news.png"];
[controller setTitle:#"View"];
[controller release];
tabBarController.viewControllers = [NSArray arrayWithObjects:controller1, controller2, controller3, controller4, controller5, nil];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
launchDefault = YES;
//[self performSelector:#selector(handlePostLaunch) withObject:nil afterDelay:0];
// Push Notification info
NSDictionary *apns = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
NSString *result = [[[apns valueForKey:#"aps"] valueForKey:#"alert"] valueForKey:#"loc-args"];
NSString *playerID = [NSString stringWithFormat:#"%#", result];
playerID = [[playerID componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:#""];
playerID = [playerID stringByReplacingOccurrencesOfString:#" " withString:#""];
playerID = [playerID stringByReplacingOccurrencesOfString:#"(" withString:#""];
playerID = [playerID stringByReplacingOccurrencesOfString:#")" withString:#""];
NSLog(#"Player ID: %#", playerID);
if (![playerID isEqualToString:#"null"]) {
if (!detailViewController) {
detailViewController = [[PlayerDetailViewController alloc] init];
}
NSManagedObjectContext *moc = [[AppController sharedAppController] managedObjectContext];
NSFetchRequest *req = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Players"
inManagedObjectContext:moc];
[req setEntity:entity];
NSPredicate *pre = [NSPredicate predicateWithFormat:#"playerID=%#", playerID];
[req setPredicate:pre];
NSError *error;
NSArray *list = [moc executeFetchRequest:req error:&error];
[req release];
Players *player = [list lastObject];
[detailViewController setPlayer:player];
//Want to Push view here
[detailViewController release];
detailViewController = nil;
}
return YES;
}
If application is launched by a notification then it will be present in the application delegate's application:didFinishLaunchingWithOptions: launchOptions dictionary under the key UIApplicationLaunchOptionsRemoteNotificationKey, which has all the info the notification has (JSON converted to NSDictionary I believe).
EDIT:
Got the question wrong, I think what you're looking for is just the pointer to the currently selected navigation controller. You get that if you query [tabbarcontroller selectedViewController], which returns the visible navigation controller. Then simply push the newly created controller on top of the stack of that navigation controller.

init an array in initWithNibName

I am trying to set up an array in my UIViewController. The nib gets loaded into my app, sometimes repeatedly. I am adding this to my initWithNibName to init the array
NSMutableArray *temp = [[NSMutableArray alloc] initWithObjects:#"one",#"two",#"three",#"four",#"five",nil];
[self setScoreArray:temp];
[temp release];
scoreArray is a MutableArray with synthesized properties. When I go to access the array in viewDidLoad I get [[self scoreArray] count] as 0. Also, when I load the nib repeatedly I get a bad access error. Any suggestions? Am I missing a step. Thanks. I am synthesizing the property for the array, in my class declaration:
NSMutableArray *_scoreArray;
then
#property (nonatomic, retain) NSMutableArray *scoreArray;
then in my implementation
#synthesize scoreArray =_scoreArray;
and in my dealloc
[_scoreArray release], _scoreArray = nil;
I'm editing this post to show how I'm loading the nibs with my RootViewController
- (void) createNewSlide:(NSInteger)slideIndex {
NSDictionary *slideObj = (NSDictionary *)[[self slidesDataSource] objectAtIndex:slideIndex - 1];
NSString *currentTitle = [slideObj objectForKey:#"title"];
[[self slideTitle] setText:currentTitle];
NSString *currentContent = [slideObj objectForKey:#"contentString"];
NSString *currentContentType = [slideObj objectForKey:#"contentType"];
if ([self currentVC] != nil) {
[[self currentVC] reset];
[self setCurrentVC:nil];
}
if ([currentContentType isEqualToString:#"slide"])
{
[[self containerViewController] loadImage:currentContent];
}
else if ([currentContentType isEqualToString:#"quiz"])
{
NSInteger quizNum = [[slideObj objectForKey:#"quizNum"] integerValue];
NSLog(#"%s%#%d",__FUNCTION__,#"quizNum ",quizNum);
QuizViewController *quizView = [[QuizViewController alloc] initWithNibName:#"QuizViewController" bundle:nil];
[self setCurrentVC:quizView];
[quizView release];
[[self containerViewController] replaceSlideWithViewController:[self currentVC]];
}
else if ([currentContentType isEqualToString:#"PIDView"])
{
PIDViewController *PIDView = [[PIDViewController alloc] initWithNibName:#"PIDView" bundle:nil];
[self setCurrentVC:PIDView];
[PIDView release];
[[self containerViewController] replaceSlideWithViewController:[self currentVC]];
}
else if ([currentContentType isEqualToString:#"LoginView"])
{
LoginViewController *login = [[LoginViewController alloc] initWithNibName:#"LoginView" bundle:nil];
[self setCurrentVC:login];
[login release];
[[self containerViewController] replaceSlideWithViewController:[self currentVC]];
}
else if ([currentContentType isEqualToString:#"VakView"])
{
VakViewController *vakView = [[VakViewController alloc] initWithNibName:#"VakView" bundle:nil];
[self setCurrentVC:vakView];
[vakView release];
[[self containerViewController] replaceSlideWithViewController:[self currentVC]];
}
else if ([currentContentType isEqualToString:#"PlanView"])
{
PlanViewController *planView = [[PlanViewController alloc] initWithNibName:#"PlanView" bundle:nil];
[self setCurrentVC:planView];
[planView release];
[[self containerViewController] replaceSlideWithViewController:[self currentVC]];
}
Thanks for your insights.
PlanView is the one that causes the problem. But it is not when it loads, it's when something else loads after it. I have run the analyzer and it reports no memory leaks.
BTW, currentVC is a synthesized property.
How is your UIViewController being created? If it is being created via another nib, then -initWithNibName:bundle: doesn't get called. Instead, -initWithCoder: and -awakeFromNib are called.