Any one have exact solution for passing image from one view to other view when using popview controller in iPhone.
Please give me some guidelines for this problem.
Thanks.
Using Protocol Delegate method use the image, or else assign your image to another controller image object and use it.
suppose your imageview is existingImageView;
.h
#interface SecondController : UIViewController
#property (retain, nonatomic) UIImageView *previousImageView;
.m
#interface SecondController ()
#end
#implementation SecondController #synthasize previousImageView;
Now in firstController while navigating use it like,
SecondController *second = [[SecondController alloc] init];
[self.navigationController pushViewController:second animated:YES];
[second setPreviousImageView:existingImageView];
[photoController release];
After Cropping Image it will reflect to existingImageView.
Related
I have a view that carries out a task, when the task is completed the activity indicator will become hidden, I want to send the user to another view when the activity is completed, or give the user an error if unsuccessful. So far I am using an If Else statement to give a success alert or an error alert. There is no buttons to click or anything, simply after the activity is completed the user will be sent to another view passing a few variables along the way.
How would I go about sending the user to another view after completion?
If you use a navigationcontroller:
[self.navigationController pushViewController:theNextViewController animated:YES];
For Storyboard, look up the method in the docu.
To elaborate on AlexWien's answer a little...
Create a view controller or table view controller class that you want
the user to go to after completion.
Create some properties for the data you want to pass in.
#protocol UpdatePricesDelegate;
#interface NXUpdatePricesViewController : UITableViewController
#property (strong, nonatomic) NSArray *calculationProducts;
#property (strong, nonatomic) NSArray *filteredCalculationProducts;
#property (weak, nonatomic) id<UpdatePricesDelegate>delegate;
#end
#protocol UpdatePricesDelegate <NSObject>
- (void)updatePricesController:(NXUpdatePricesViewController *)controller didUpdateCalculationProducts:(NSArray *)calculationProducts;
#end
When you are ready to display your controller (presumably in your If/Else statement), instantiate the class (don't forget #import "MyClassName.h") and set the properties to the variables you want to pass.
Present the class modally (example includes a navigation controller), or if you want to push the view, use your navigation controller.
NXUpdatePricesViewController *updatePricesController = [[NXUpdatePricesViewController alloc] initWithStyle:UITableViewStyleGrouped];
updatePricesController.delegate = self;
updatePricesController.calculationProducts = self.calculationProducts;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:updatePricesController];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self.navigationController presentViewController:navigationController animated:YES completion:nil];
NXCalculationViewController *calculationController = [[NXCalculationViewController alloc] init];
calculationController.calculation = calculation;
[self.navigationController pushViewController:calculationController animated:YES];
I actually got it working, along with passing a variable to the other view using this method:
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"DetailView"];
[detail setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
detail.videoURL = outputURL;
I have a view whose controller is being instantiated (NSLog says so), but the view doesn't show up. If I load it as a modal view it appears, but not if I allocate it.
I have this structure (MenuView is the view that doesn't appear):
// ViewController.h
#import "MenuViewController.h"
#class MenuViewController;
#interface ViewController : UIViewController<ASIHTTPRequestDelegate>{
...
IBOutlet MenuViewController *menuView;
}
...
#property(nonatomic, retain) MenuViewController *menuView;
#end
// ViewController.m
#import "MenuViewController.h"
#implementation ViewController
#synthesize menuView;
- (void)loadMenu{
// THIS WORKS
// [self presentModalViewController:menuView animated:YES];
// THIS DOESN'T (VIEWCONTROLLER IS INSTANTIATED BUT VIEW DOESN'T APPEAR
menuView = [[[MenuViewController alloc] initWithNibName:#"MenuView" bundle:Nil] autorelease];
[self.navigationController pushViewController:menuView animated:YES];
}
Some ideas:
Try using self.menuView when assigning:
self.menuView = [[MenuViewController alloc] initWithNibName:#"MenuView" bundle:Nil];
Also, probably shouldn't autorelease a property. Release it in dealloc and set it to nil in viewDidUnload.
Make sure that self (ViewController) has a navigationController. Was ViewController pushed/presented by a navigationController?
Is - (void)loadMenu{ being called from the MainThread? Check with [NSThread mainThread]
Check out some tutorials/examples:
Adding a Navigation Controller by Hand
NavigationController Application in iPhone
Tutorial: Introducing UINavigationController Part 1
iPhone View Switching Tutorial
I have a root view controller which should load another view controller as soon as it is done loading (i.e. in the viewDidLoad method).
I am using the UINavigationController in order to push a new view controller onto the stack:
In my rootviewcontrollerappdelegate:
-(void) viewDidLoad{
LoginViewController* lvc = [[LoginViewController alloc]init];
[self.navigationController pushViewController:lvc animated:NO];
}
I have textfields and buttons in the view controller to be loaded. The above doesn't seem to work however...It loads just a blank grey screen and no UINavigation bar is present. If I comment out the second line (pushViewController line), then I see the navigation bar. So I think it is loading something, but the items in the view controller being loaded are not being shown...Any ideas why?
Check if navigationController is pointing to nil. If it does, try
[self.view addSubview:self.pushViewController.view]
I had the same problem and found the above solution here:
UIViewController -viewDidLoad not being called
Unless you're doing something tricky, you should be calling alloc on the LoginViewController class rather than a variable. Also, if you've set up LoginViewController in Interface Builder (as opposed to programmatically), you'll need to load it from an NIB:
LoginViewController *lvc = [[[LoginViewController alloc] initWithNibName:nil bundle:nil] autorelease];
[self.navigationController pushViewController:lvc animated:NO];
Have a look at initWithNibName:bundle: in the docs.
Not entirely sure what you are trying to achieve but when you instantiate LoginViewContoller it should probably look like this
LoginViewController* lvc = [[LoginViewController alloc]init];
Judging by the nature of your naming for your view controller, is your LoginViewController the first view controller for your UINavigationController?
If that is what you're trying to do, you should instead initialise your navigation controller with the LoginViewController as the root controller instead of pushing it onto the navigation stack.
UINavigationController has a method to do this:
- (id)initWithRootViewController:(UIViewController *)rootViewController
EDIT:
Well, one way you can go about it is like this.
In your application delegate .h file, you should have declared a UINavigationController.
#interface MyAppDelegate : NSObject <UIApplicationDelegate>
{
UINavigationController *navController;
}
#property (nonatomic, retain) UINavigationController *navController;
#property (nonatomic, retain) IBOutlet UIWindow *window;
#end
In your App Delegate didFinishLaunching:withOption: you can create an instance of your LoginViewController there, and use that to init your UINavigation controller as the root view controller
#import "LoginViewController.h"
#implementation MyAppDelegate
#synthesize navController;
#synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
LoginViewController *loginController = [[LoginViewController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:loginController];
[loginController release];
[[self window] setRootViewController:navController];
[navController release];
[self.window makeKeyAndVisible];
return YES;
}
I probably have a typo here or there but that's one way I would go about doing it.
I have an application which has a view called store. In this view there is a button which loads the DetailView. Problem is that this detailview doesn't load/show. This is the code I use:
-(void)knop:(id)sender{
categoryView = [[CategoryView alloc] init];
//show detail view using buttonDetail...
[self.navigationController pushViewController:categoryView animated:YES];
[categoryView release];
NSLog(#"Button is working");
}
The log "Button is working" logs, so the pushViewController line is also triggered.
categoryView is made in my .h file:
CategoryView IBOutlet *categoryView;
}
#property (nonatomic, retain) IBOutlet CategoryView *categoryView;
In the store.xib there is a UIViewController with an outlet linked to the categoryView outlet.
Somewhere else in my app this is working, and I can't seem to find out why this one isn't
Any help would be appreciated!
THNX
Did you assign the UINavigationController in your AppDelegate?
#interface
#property (nonatomic, retain) IBOutlet RootViewController *rootViewController;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#implementation didFinishLaunchingWithOptions
rootViewController = [[RootViewController alloc] initWithNibName:#"RootView" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
pushViewController works fine then through the whole App.
It sounds like
NSLog(#"nav controller = %#", self.navigationController);
will show that navigationController is nil.
I suggest creating a new project of navigation type and see how this should be setup.
I have found it. Since I was using a tabbar based app, I needed to change the store tab to Navigation Controller. When I changed it, it worked! Thanks for all your support!!!
If your view is nib based, you need to use:
categoryView = [[CategoryView alloc] initWithNibName:nibName bundle:nibBundle];
Hope this helps.
I am trying to present a image selector to my user while they are on a view presented as modal view.
I am building the view in a table view app. Right now the code runs but does not open the ImagePicker.
In DetailTableViewController.m
#implementation DetailTableViewController
There is an (+) button in the nav and when it is clicked I call
- (void)add
{
DetailTableViewController *controller = [[DetailTableViewController alloc]
initWithStyle:UITableViewStyleGrouped];
UINavigationController *newNavController = [[UINavigationController alloc]
initWithRootViewController:controller];
newNavController.delegate = self;
[[self navigationController] presentModalViewController:newNavController
animated:YES];
DetailTableViewController *controller2 = [[DetailTableViewController alloc]
initWithStyle:UITableViewStyleGrouped];
imgPicker = [[UIImagePickerController alloc]
initWithRootViewController:controller2];
imgPicker.allowsEditing = YES;
imgPicker.delegate = self;
//______________HERE I CREATE THE INTERFACE FOR THIS VIEW IN CODE__________________
NSLog(#"Load add View");
}
One of the button on this page is a select image button which is here:
- (IBAction)grabImage {
[newNavController pushViewController:imgPicker animated:YES];
NSLog(#"grabImage");
}
This does not present the imgPicker view. But the button click is logged.
I have in the top of file: DetailTableViewController.m
#implementation DetailTableViewController
#synthesize imgPicker;
In DetailTableViewController.h
#interface DetailTableViewController : UITableViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextViewDelegate> {
MWFeedItem *item;
NSString *dateString, *summaryString;
IBOutlet UIWebView *webview;
IBOutlet UIButton *dismissViewButton;
UIImagePickerController *imgPicker;
UINavigationController *newNavController;
IBOutlet UIButton *upload;
IBOutlet UIButton *doneEdit;
IBOutlet UIImageView *image;
}
How can I make the imgPicker display?
I have tried:
using presentModalViewController instead of push in grabImage
List item many combinations of which controller imgPicker is presented to. With some
I get the error: (Application tried to present a nil modal view controller on target)
several variations from this question:
iPhone modal view inside another modal view?
UPDATED including corrections from #aBitObvious, but the issue remains.
#aBitObvious pointed me to the answer. The local override turned out to be the answer but not on imgPicker but on newNavController.
Thanks again!