How to force UIView to accept only last touch event - ipad

I've created one customView,in which, on click event it shows imagepicker selection option.I've added 5 instances on customView in other View say 'myView'.
Now in 'myView' if user selects all 5 views at same time.Then 'myView'shows 5 imagePicker selection option.How to force 'myView' to recognize last touch.so that it should show only one imagePicker selection or it should dismiss other popover when user selects Gallery/Camera.
.

Create a UIPopoverController instance in your customView
like this...
.h file:
#property (strong, nonatomic) UIPopoverController *popover;
Then, when you need the popover to show up, instaniate it like this (.m file):
self.popover = [[UIPopoverController alloc] initWithContentViewController:someViewController];
Now there will always be just only one Popover shown

Related

Is it possible to replace the UIView behind a popover (or a modal view) based on the popover actions?

Need to implement a popover (or a modal view), and based on selection in the popover, may go to another view once the popover is closed
Yes, you can. Add delegate to popover, and trigger an action after the select. Then you can do whatever you want based on results of popover. If you need some more help please provide some code.
I will try to help you without your code:
Create protocol for the method you want to trigger:
#protocol someMethodDelegate
- (void)functionYouWantToTrigger;
#end
In your view controller(MyViewController) from which you call your popover .h file:
#interface MyViewController<someMethodDelegate>
In your .m file for MyViewController you have declaration like:
MyPopOver *popover = [[MyPopOver alloc] init];
popover.delegate = self;
Later on, in your .m file:
- (void)functionYouWantToTrigger{
//do some wild things here
}
And lastely, in your popover on some event:
[self.deleagate functionYouWantToTrigger];
You can expend this method with attributes as you wish.

ios:How to persist object value in viewcontroller

I am having one view controller WebViewController and second is Settings. On tap of button i am adding Settings view controller as subview of webviewcontroller.
menusettings=[self.storyboard instantiateViewControllerWithIdentifier:#"SET"];
[menusettings.view setFrame:CGRectMake(0, 0, 700,600)];
[self.view addSubview:menusettings.view];
I have Webview Object in the
Webview controller
#property (strong, nonatomic) IBOutlet UIWebView *wrae_one;
and i am loading data in webview but when i cal function from Settings controller then the value self.wrae_one becoming null. Means when i add setting view controller as subview in webview controller then obejet of webview become null. Is there any way to main it value. In settings i am using this code for calling the function
self.home_webview=[[PRGVwebViewController alloc]init];
[self.home_webview loadWebviewController]
I think that PRGVwebViewController is the class from which the settingsviewcontroller is instantiated. So why do you re alloc the class? Doing this you are creating a new controller, but when you dismiss the settingsviewcontroller, you are seeing the first one.
You have to create a reference to the previous controller.
Maybe, the best way is to instantiate the WebViewController as a sharedIstance (singleton), so you can access to it (and only it) wherever you want.
This can be helpful: http://www.daveoncode.com/2011/12/19/fundamental-ios-design-patterns-sharedinstance-singleton-objective-c/

Display UIview controller as a subview using storyboard IOS7

in my application I have a UIView object in second view controller. Now I want to display the UIView as a popup or sub view when I click the button from first view controller. Please tell me how to do this? I have seen many solution for the nib files but I didn't find any for storyboard.
I have connected the IBOulet of view in my second view controller.
#property (strong, nonatomic) IBOutlet UIView *popview;
And i have imported the second view controller in my firstview please tell me how to make this one i have been stuck here for long time please help me out on this one.
Thanks.
In your FirstViewController which has UIView *popview:
- (void)viewDidLoad
{
[super viewDidLoad];
// you don't want to show PopView
self.popview.alpha = 0;
}
- (void) showPopView
{
//you want to show PopView
self.popview.alpha = 1;
}
Try Adding this in your code
-(void)viewDidLoad
{
popView.hidden=true;
}
and when ever user clicks an action change the hidden property to false just like
-(IBAction)AnyActionPerferformed:(id)sender
{
popView.hidden=false;
}
You can Learn about this from
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/AboutViewControllers/AboutViewControllers.html
You don't need an extra UIViewController
In your storyboard, drag a new UIView to your view controller. (It will be your popup view)
Link to your view controller. (#property (strong, nonatomic) IBOutlet UIView *popview;)
When you want to hide popview set it's alpha to 0.

Create Container view for Two UIViewController on iPad

i have two UIViewController class with xib from interface builder, and i want create another UIViewController with xib that contains this two view, it's possible and how i can achieve this feature?
You can't add View controller A and B's views to view controller C in an XIB because there is a fair amount of housekeeping code you need to do to set up the parent/child view controller relationship.
However, if you were to use storyboards, and you are running in iOS 6 or later, this would be trivial. There is a new "container" view in iOS 6. You just add a container view to your scene, and then control-drag from the container view onto another view controller's scene, and IB sets up an embed segue that does all the housekeeping for you. In my view this feature alone is enough to justify moving to storyboards.
You add two UIView in your third UIViewController xib and you link these UIView with IBOulet.
#property (nonatomic, weak) IBOutlet UIView *firstView;
#property (nonatomic, weak) IBOutlet UIView *secondView;
After that you add your UIViewController in theses subviews in the viewDidLoad for example :
- (void)viewDidLoad
{
[super viewDidLoad];
MyFirstViewController *myFirstViewController = [[MyFirstViewController alloc] initWitNibName:#"MyFirstViewController"];
MySecondViewController *mySecondViewController = [[MySecondViewController alloc] initWitNibName:#"MySecondViewController"];
[self.firstView addSubview:myFirstViewController.view];
[self.secondView addSubview:mySecondViewController.view];
}
Improve it with #property of First and Second ViewController and Lazy loading.

initWithNibName help: returning blank screen when trying to pass data

Ok so I am trying to pass a string from one view controller to another via the AppDelegate. I want to stay on the current view while this happens.
This is the main body of the code I am currently using to do this:
AppDelegate *dataCenter = (AppDelegate *)[[UIApplication sharedApplication] delegate];
MyMealViewController *vc = [[MyMealViewController alloc] initWithNibName:nil bundle:nil];
dataCenter.selectedMenuItem = recipeLabel.text;
[self presentViewController:vc animated:YES completion:NULL];
When I run the program I am able to confirm that the string is correctly passed. However, then the view on the simulator just turns black. I assume that this is because initWithNibName is set to nil.
So my question is: how should I change my code so that the string will still be passed, but the current view will continue to be displayed on the iphone. Is there a line of code that I could write that would just reload the current view?
Thanks for your help with this issue. I am new to xcode so I may be making a very basic error. Please let me know if any additional information would be helpful in answering this question.
Edit: It looks like you want to show a list of food items in the first view. Tapping an items opens a detail view. From that detail view, the user can press a button to add it to the meal. Eventually, they can tap a button on the first view to open the meal view, which should contain all of the items that they selected.
If this is the case, keep an array on the first view controller, and make sure the detail (second) view controller has a reference to the first view controller when it is presented. This will let us use that array. Note that there are better ways to architect this, but this will work for now:
#interface FoodListViewController : UIViewController
#property (strong, nonatomic) NSMutableArray *foodItems
#end
#implementation FoodListViewController
- (void)showFoodItem
{
FoodItemDetailViewController *detailViewController = [[FoodItemDetailViewController alloc] initWithNibName:nil bundle:nil];
detailViewController.foodListController = self;
[self presentModalViewController:detailViewController animated:YES];
}
#end
Once the detail view is presented, tapping the 'add to meal' button should add the current 'mealItem' to the array. In your example, you were using strings - if you would rather keep an array of strings for some reason, I'll leave that to you.
#interface FoodItemDetailViewController : UIViewController
#property (nonatomic, weak) FoodItemsViewController *foodListController;
#end
#implementation FoodItemDetailViewController
- (IBAction)buttonTapped:(id)sender
{
[self.foodListController.foodItems addObject:self.mealItem];
// Update the UI to let the user know that the item was added to the meal
}
#end
Finally, when it comes time to present the MealDetailsViewController, just pass it the array that you have been building:
#interface MealDetailsViewController : UIViewController
#property (nonatomic, strong) NSArray *foodItems;
#end
#implementation MealDetailsViewController
// Set foodItems before this view controller is presented, then use it to drive the
// UITableView data source, or find some other way of displaying it.
#end
As you can see, both the second and third view controllers are presented by the first. View controllers (nearly) always form a hierarchy - so keeping your data at the top of that hierarchy (by storing it in FoodListViewController) lets you neatly pass it down the hierarchy as you present other view controllers.

Resources