So, I think that when I click outside of a popover, the method popoverControllerDidDismissPopover should be called. I know this isn't called when dismissPopoverAnimated is called.
I have a simple project that I have setup that shows popoverControllerDidDismissPopover just isn't called:
#import "ViewController.h"
#import "PopoverViewController.h"
#interface ViewController ()
{
PopoverViewController *controller;
UIPopoverController *popoverController;
}
#end
#implementation ViewController
#synthesize button;
- (IBAction)showPopover:(UIButton *)sender
{
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
} else {
CGRect popRect = CGRectMake(self.button.frame.origin.x,
self.button.frame.origin.y,
self.button.frame.size.width,
self.button.frame.size.height);
[popoverController presentPopoverFromRect:popRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
controller = [[PopoverViewController alloc] initWithNibName:#"PopoverViewController" bundle:nil];
popoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
NSLog(#"Why am I never called!!!!");
}
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return true;
}
#end
Please tell me where I'm going wrong or how I can detect when a popover is dismissed.
The whole project is here:
https://rapidshare.com/files/3182903825/PopoverDemo.zip
You never set the delegate for your popoverController to self.
_popoverController.delegate = self;
You didn't set the delegate of your popoverController. Add the following code to the end of the viewDidLoad method:
popoverController.delegate = self;
Related
I saw similar questions like this. In all the place they said to use className.delegate = self or other similar solutions. But i already checked i have did everything correctly. Then also i am facing self.delegate is nil problem.
I am trying to pass data from MyViewController to NextViewController on Button Click
I did,
1.Created Protocol in MyViewController
2.Created delegate Instance in MyViewController
3.Wrote this code in Button Click Event
-(void)buttnPressed:(id)s{
NextViewController* d=[[NextViewController alloc]init];
if(self.delegate){
NSLog(#"D");
}
if (self.delegate && [self.delegate respondsToSelector:#selector(groupSelected:)]) {
[self.delegate groupSelected:#"df"];
}
[self.navigationController pushViewController:d animated:YES];
}
4.Implemented FirstViewController in NextViewController and set it's delegate
5.Created FirstViewController's instance (inside NextVC) and using that instance i set it's delegate as self
6.Implemented the delegate method in NextVC
I did everything correctly to my knowledge but i did not get the solution. Please help. Thanks for the time. (:
Here is my code
MyViewController.h
#import <UIKit/UIKit.h>
#protocol WatchListDelegate <NSObject>
-(void)groupSelected:(NSString *)grouDetails;
#end
#interface MyViewController : UIViewController
#property (strong,nonatomic) id<WatchListDelegate> delegate;
#end
MyViewController.m
#import "MyViewController.h"
#import "NextViewController.h"
#interface MyViewController ()
#property UIButton *buttonPopUp;
#end
#implementation MyViewController
-(id)init{
self = [super init];
return self;
}
-(void)loadView{
[super loadView];
self.buttonPopUp=[UIButton buttonWithType:UIButtonTypeCustom];
[self.buttonPopUp addTarget:self
action:#selector(buttnPressed:)
forControlEvents:UIControlEventTouchUpInside];
[self.buttonPopUp setTitle:#"Press ME" forState:UIControlStateNormal];
[self.buttonPopUp setBackgroundColor:[UIColor blueColor]];
self.buttonPopUp.frame=CGRectMake(80,180,80,40);
[self.view addSubview:self.buttonPopUp];
}
-(void)buttnPressed:(id)s{
if(self.delegate){
NSLog(#"D");
}
if (self.delegate && [self.delegate respondsToSelector:#selector(groupSelected:)]) {
[self.delegate groupSelected:#"df"];
}
NextViewController* d=[[NextViewController alloc]init];
[self.navigationController pushViewController:d animated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
#end
NextViewController.h
#import <UIKit/UIKit.h>
#import "MyViewController.h"
#interface NextViewController : UIViewController<WatchListDelegate>
#end
NextViewController.m
#import "NextViewController.h"
#interface NextViewController ()
#end
#implementation NextViewController
-(id)init{
self = [super init];
if(self){
MyViewController *m=[[MyViewController alloc]init];
m.delegate = self;
}
return self;
}
-(void)loadView{
[super loadView];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void)groupSelected:(NSString *)grouDetails{
NSLog(#"groupSelected");
}
#end
Thanks for the time (:
Try This:
-(void)buttnPressed:(id)s{
NextViewController* d= [self.storyboard instantiateViewControllerWithIdentifier:#"VCidentiferFromStoryBoard"];
self.delegate = d;
[self.navigationController pushViewController:d animated:YES];
if (self.delegate && [self.delegate respondsToSelector:#selector(groupSelected:)]) {
[self.delegate groupSelected:#"df"];
}
}
I don't think you need a delegate to pass data, you're trying to pass the string value 'df'? If so you could just create a public property in NextViewController and assign it a value when you create NextViewController in MyViewController?
The delegate is nil, because it does not look like you set it, so in the button pressed logic you would do self.delegate = d;, don't assign the delegate or create MyViewController in the init of NextViewController, then check the delegate and it won't be nil, but I don't think you need the delegate pattern in this case?
Let me know if you need me to clarify or there is something else in particular you need to pass.
Edit your MyViewController.m
#implementation MyViewController
{
NextViewController* nextViewController;
}
Then rewrite the buttnPressed method like below:
-(void)buttnPressed:(id)s
{
if(!nextViewController) // this way only one time NextVC will be created
{
nextViewController = [[NextViewController alloc]init];
[self.navigationController pushViewController:nextViewController animated:YES];
self.delegate = nextViewController;
}
if (self.delegate && [self.delegate respondsToSelector:#selector(groupSelected:)]) {
[self.delegate groupSelected:#"df"];
}
}
I have a UIViewController called TestViewController.h/.m:
Header file has:
#property (nonatomic, assign) BOOL isTested;
Implementation file has:
#implementation TestViewController
- (void)viewDidLoad
{
if (_isTested)
{
[self postNotification];
[self listenToNotifications];
}
}
I have a view that has this:
- (void) replyTapPressed
{
TestViewController *test = [[TestViewController alloc] init];
test.isTested = NO;
[_parent.navigationController pushViewController:test animated:YES];
}
Through the app's life cycle, the TestViewController's property starts off as YES; but when the view about gets called, it should set the property to NO; - which it does.
But _parent (which is the parent UIViewController) and test are both NULL.
Am I initializing and implementing it wrong?
Thanks.
You may try in below ways -
TestViewController.m
- (id)initWithTested:(BOOL)value
{
if (self = [super init])
{
self.isTested = value;
}
return self;
}
- (void) replyTapPressed
{
TestViewController *test = [[TestViewController alloc] initWithTested:NO];
[_parent.navigationController pushViewController:test animated:YES];
}
The view will "load" during initialization of your controller. To achieve what you want, implement viewWillAppear and move
if (_isTested) {
[self postNotification];
[self listenToNotifications];
}
there. (You could also put this in viewDidAppear, depending on what you are doing.)
I', performing a basic push segue (working with nibs) and from one view controller to another table view controller, and from some reason the 'Back' button is not appearing, that normally it does appear.
This is how i'm performing the push:
#interface HomeViewController ()
#end
#implementation HomeViewController
- (id)init {
self = [super initWithNibName:#"HomeViewController" bundle:nil];
if (self) {
// Do something
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (IBAction)goToStack:(id)sender {
StackTableViewController *stackViewController = [[StackTableViewController alloc] initWithNibName:#"StackTableViewController" bundle:nil];
[self.navigationController pushViewController:stackViewController animated:YES];
}
In your StackTableViewController, you should set setNavigationBarHidden to NO
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
To make sure the navigation bar reappears every time you navigate away from your view controller (HomeViewController), use this:
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
I have added UINavigationBar in appDelegate method. Please check my atatched screen shots. In bottom is i have used UINavigationBar. In middel of the page history button is there.
Here when i click the history button its cant go to historyviwcontrooler. Because i cant push the view. Can you please tell me how i can push here. When i click history its called only one calls after only thet called another class there only i given UI. How i handel here . please help me
#import "UICallButton.h"
#import "LinphoneManager.h"
#import <CoreTelephony/CTCallCenter.h>
#implementation UICallButton
#synthesize addressField;
#pragma mark - Lifecycle Functions
- (void)initUICallButton {
[self addTarget:self action:#selector(touchUp:) forControlEvents:UIControlEventTouchUpInside];
}
- (id)init {
self = [super init];
if (self) {
[self initUICallButton];
}
return self;
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initUICallButton];
}
return self;
}
- (id)initWithCoder:(NSCoder *)decoder {
self = [super initWithCoder:decoder];
if (self) {
[self initUICallButton];
}
return self;
}
- (void)dealloc {
[addressField release];
[super dealloc];
}
#pragma mark -
- (void)touchUp:(id) sender {
NSString *address = [addressField text];
NSString *displayName = nil;
ABRecordRef contact = [[[LinphoneManager instance] fastAddressBook] getContact:address];
if(contact) {
displayName = [FastAddressBook getContactDisplayName:contact];
}
[[LinphoneManager instance] call:address displayName:displayName transfer:FALSE];
}
#end
Basically, you must have a UINavigationController, and not just a UINavigationBar, in order to be able to perform a push transition to one UIViewController to another.
I'm not explaining how to do that because it's very basic, you should study and read some books/tutorials before begin a real project.
Here's some links to help you:
A nice tutorial
How to use navigation controllers (from apple)
Navigation Controller class reference
Good day to you guys
I have an application that has a UITabBarController for tabbed-navigation... The view-controllers are mapped to their respective TabItems via a URL, just the same as that of Three20's TTNavigationSample App.
My problem is that inside a view controller of mine, i have a button that calls to another view controller which is also attached to a TabItem. When i trigger the button, the application throws an error. How can I resolve this?
In my TabBarController, i have this inside the viewDidLoad method:
-(void)viewDidLoad {
[self setTabURLs: [NSArrayWithObjects:
#"tt://bulletinBoard",
#"tt://contacts",
nil
]];
}
Sample .m file
#import "HabBarController.h"
#implementation TabBarController
- (void)viewDidLoad {
//these are variables like "tt/feed"
[self setTabURLs:[NSArray arrayWithObjects:
kAppFeedURLPath,
kAppHotURLPath,
kAppPostPhotoURLPath,
kAppGeneralActivityURLPath,
nil]];
}
- (UIViewController*)rootControllerForController:
(UIViewController*)controller {
if ([controller canContainControllers]) {
return controller;
} else {
UINavigationController* navController = [[[UINavigationController
alloc] init] autorelease];
[navController pushViewController:controller animated:NO];
return navController;
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.tabBarController.navigationController setNavigationBarHidden:YES animated:NO];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[super dealloc];
}
#end