I'm having to class one which extends NSObject and second the view controller.
What is my problem is that I want to go to NSObject to view controller that loads my xib file of that view controller.
I have used the traditional, with no success thus far.
Suppose NSObject is MagentoLogin.m and I want to go to viewController, how can I achieve this?
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.navigationController presentViewController:myNewViewController animated:YES completion:nil];
try this hope it will help
Related
How can I reload data of UIVIewcontroller from the UIView.Actually I have a UIVIewController which has a Custom class class of UIView .Now In UIViewcontroller i have a label and i need to print values of label which is been defined in the UIView.
but viewdidload of the UIViewController is been compiled firstly then compiler moves to UIView.then how can I print or Reload the UIVIewController
. UILabel Text I have defined in the ViewDidLoad of UIViewController and values taken from the UIView class
So How can I reload the UIViewController.
what I am doing is:
UIVIewController(thirdTab) class
-(void)viewDidLoad{
[self reloadInputViews1];
}
-(void)reloadInputViews1{
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
// labelPrint.text=appDelegate.dayPrint;
[self.labelPrint setText:labelPrint.text];
}
UIView class
- (void)drawRect:(CGRect)rect {
AppDelegate* appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.dayPrint=theDate;
NSLog(#"appde%#",appDelegate.dayPrint);
[appDelegate.thirdTab reloadInputViews1];
}
But this does not work ...I am not able to print values in the label.how to do that..to get values from the UIViews
You can call setNeedsDisplay on your view to force it to be redrawn. But I am not sure that this is the best solution, in fact, instead of calling setNeedsDisplay on your view, you could call directly reloadInputViews1 on your controller and it would be the same (actually, it would be much better).
Apart from this, I donĀ“t think that your current design is very clean. I would suggest you to define a delegate protocol between your view and your controller to make that kind of relationship more explicit.
how to call an AppDelegate method from RootViewController without passing a delegate?
Just wondering whether there is a way to do this? (or do I need to create a delegate object in the RootViewController to hold a reference to the AppDelegate)
[[[UIApplication sharedApplication] delegate] someMethod];
Works like a charm!
You can get access to the app delegate from any controller using
MyDelegate* aDelegate = (MyDelegate *)[[UIApplication sharedApplication] delegate];
This happens so frequently, that I always add a method to MyCustomAppDelegate to do this for me (so I don't have a lot of casting in my code.
#implementation MyCustomAppDelegate ()
- (MyCustomAppDelegate *)appDelegate {
return (MyCustomAppDelegate *)[[UIApplication sharedApplication] delegate];
}
#end
now anywhere i can call
[MyCustomAppDelgate appDelegate]
I need to share data from a "SampleAppdelegate" to two view controller "ContactViewController.m" and "DrinksViewController.m".
In SampleAppdelegate:
#interface SampleAppdelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate , UINavigationBarDelegate>
So I've included below code in respective view controller.
In ContactViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
SampleAppDelegate *appDelegate = (SampleAppDelegate *)[[UIApplication sharedApplication] delegate];
contactDatabaseObject = (ContactDatabaseObject *)[appDelegate.contactDetails objectAtIndex:0];
NSLog(#"%#", contactDatabaseObject.contactName);
[appDelegate release];
}
In DrinksViewController.m
(void)viewDidLoad
{
[super viewDidLoad];
SampleAppDelegate *appDelegate = (SampleAppDelegate *)[[UIApplication sharedApplication] delegate];
drinksDatabaseObject = (DrinksDatabaseObject *)[appDelegate.drinkDetails objectAtIndex:0];
NSLog(#"%#", drinksDatabaseObject.drinkName);
[appDelegate release];
}
The problem is "sharing application delegate is is both of the code not working at the same time. ( that is, if I comment above in a view controller then other is working fine as as expected).
Actually i'm using a tab-bar with two item as above viewControllers. So loading of the first controller happens fine. But when i click the second view controller the iphone-simulator is terminated with any warning. ( And at the same time the code works normal if I comment it in any one of the view controller). Please help me to resolve above issues or suggest a method to accomplish above feature.
Thanks in advance !
You should read ...
http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/MemoryMgmt/MemoryMgmt.html
You're not owner of appDelegate, no need to release it.
P.S. If you're asking for help and writing something about warning, you should always copy warning here to shed more light on your problem.
You should not be releasing the appDelegate.
In my subclass of NSObject I would like to call something like
[[self navController] presentModalViewController:myView animated:YES];
But none of my tries were successful. How can I call a modal view if I'm not in a subclass of UIViewController?
Solution:
#import "myProjectNameAppDelegate.h"
// ...
MyViewController *myView = [[MyViewController alloc] init];
myProjectNameAppDelegate *appDelegate = (myProjectNameAppDelegate *)[[UIApplication sharedApplication] delegate];
[[appDelegate navController] presentModalViewController:myView animated:YES];
better way to call a presentModalViewController is, passing viewcontroller to the NSobject class. call the nsobject function from the uiviewcontroller
Here is the code with mail example
In view Controller //your current view
[nsobjectclassObject OpenMailComposer:self]; //this will take the viewcontroller to NSobject class
In NSObject class //may be sharing class
-(void)OpenMailComposer:(UIViewController*)view
{
viewControllertoShow = view; // viewControllertoShow is UIVIewcontroller object
MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc]init];
mailView.mailComposeDelegate = self;
[mailView setSubject:#"Hey! check this out!"];
[viewControllertoShow presentModalViewController:mailView animated:YES];
}
For dismissing from NSObject class you can do the following
[viewControllertoShow dismissViewControllerAnimated:YES]
I don't see a way to display a modal view without a ViewController. You have to store a reference to a UIViewController in your class so you can access it. Or setup a property in your AppDelegate, which you can get by calling [[UIApplication sharedApplication] delegate];
If you hold the navigationController or some viewController, you can present a modal view controller.
What is your myView? Is it a view, is it a viewController. I hope that it is a viewcontroller otherwise, this is the reason your code doesn't run
So I have a UIWebView implemented in one .m file and a UITableView implemented in another. When a user clicks UITableView element, the UIWebView appears. The problem is that I have to set UIWebView's content (local text and images) depending on the UITableView's row number. I know how to do this, but this, of course must be implemented with the UITableView but it also needs UIWebView.
Just importing the UIWebView implementation does'n work.
Thanks in advance!
see this link to for setting delegates here
In didSelectRowAtIndexpath
NSString *name=#"content of table";
myAppDelegate *appDelegate = (myAppDelegate *) [[UIApplication sharedApplication] delegate];
[appDelegate setCurrentTitle:name];
PictureWebViewController *webview = [[PictureWebViewController alloc] initWithNibName:#"PictureWebViewController" bundle:nil];
[self.navigationController pushViewController:email animated:YES];
the PictureWebViewController is class of your webview .
In that class in viewdidload method get the title as
myAppDelegate *appDelegate = (myAppDelegate *) [[UIApplication sharedApplication] delegate];
NSString *name= [appDelegate getCurrentTitle];
Use the name in this class to display the content in webview.
All the Best