KieranLafferty / KLNoteViewController

A view controller that organizes multiple navigation controllers in a stack inspired by Evernote 5.0 app
Other
923 stars 147 forks source link

How can i update one of viewcontollers when i go to KLControllerCardStateDefault state? #13

Closed leoru closed 11 years ago

leoru commented 11 years ago

Hi! I want to delete buttons from navbar in contollers when i go to KLControllerCardStateDefault state, but I did not get.

I tried to do:

-(void) noteViewController: (KLNoteViewController) noteViewController didUpdateControllerCard:(KLControllerCard)controllerCard toDisplayState:(KLControllerCardState) toState fromDisplayState:(KLControllerCardState) fromState {

if (toState == KLControllerCardStateDefault) { NSIndexPath path = [self indexPathForControllerCard:controllerCard]; TDListViewController viewController = (TDListViewController *)[self noteView:self viewControllerForRowAtIndexPath:path]; [viewContoller updateUI]; }

}

// updateUI in TDListViewController -(void)updateUI1 { self.navigationItem.leftBarButtonItem = nil; }

KieranLafferty commented 11 years ago

What is the behaviour when you do this? Although you are using the control to organize your UINavigationControllers, the behaviour of the navigation controllers will not change as a result of being contained within the KLNoteViewContoller.

I would attempt to do it using the method call rather than the accessor. i.e. try [self.navigationItem setLeftBarButtonItem: nil animated: YES/NO];

leoru commented 11 years ago

The behaviour - nothing happens. i tried [self.navigationItem setLeftBarButtonItem: nil animated: YES/NO]; nothing happens.

The problem, that if i set action on button within view: -(void)DeleteLeftItem:(id)sender { [self updateUI]; } and press this button, leftbaritem will be removed, but when i call updateUI in noteviewcontroller delegate, nothing happens.

KieranLafferty commented 11 years ago

Have you put a breakpoint to see if the code is being executed?

On 2013-02-27, at 11:37 AM, Kirill Kunst notifications@github.com wrote:

The behaviour - nothing happens. i tried [self.navigationItem setLeftBarButtonItem: nil animated: YES/NO]; nothing happens.

The problem, that if i set action on button within view: -(void)DeleteLeftItem:(id)sender { [self updateUI]; } and press this button, leftbaritem will be removed, but when i call updateUI in noteviewcontroller delegate, nothing happens.

— Reply to this email directly or view it on GitHub.

leoru commented 11 years ago

Ofcause, the code executed, but nothing happens.

leoru commented 11 years ago

i tried set navbar title in updateUI, but I did not get

KieranLafferty commented 11 years ago

Ah I think I know what is wrong

you need to do

self.navigationController.navigationItem.leftBarButtonItem = nil;

KieranLafferty commented 11 years ago

otherwise check fi self.navigationItem is nil or not to see if you are actually referencing anything

leoru commented 11 years ago

i tried self.navigationController.navigationItem.leftBarButtonItem = nil; nothing happens.

and i check self.navigationItem is nill or not - it's not nil.

leoru commented 11 years ago

Can you try to add 3-4 viewcontrollers to klnoteviewcontroller and update title or right or left bar item when viewcontrollers go to KLControllerCardStateDefault state? Maybe i do anything wrong.

KieranLafferty commented 11 years ago

tbh this is a navigationcontroller issue not related to the control. As mentioned previously the control just organizes UIViewControllers, what you do with the UIViewControllers/UINavigationControllers is up to you. Try performing the same operation with the UINavigationController outside of the control and see if it works

leoru commented 11 years ago

Try performing the same operation with the UINavigationController outside of the control and see if it works I try to change nav item title and rightbaritem from uibutton action and everything is ok. but when i try to do this in -(void) noteViewController: (KLNoteViewController) noteViewController didUpdateControllerCard:(KLControllerCard)controllerCard toDisplayState:(KLControllerCardState) toState fromDisplayState:(KLControllerCardState) fromState {}, nothing happens,unfortunately

KieranLafferty commented 11 years ago

Try

if (toState == KLControllerCardStateDefault) { NSIndexPath path = [self indexPathForControllerCard:controllerCard]; TDListViewController viewController = (TDListViewController *)[self noteView:self viewControllerForRowAtIndexPath:path]; viewController.navigationController.navigationItem.leftBarButtonItem= nil; }

}

KieranLafferty commented 11 years ago

just throwing out ideas... :P

leoru commented 11 years ago

i tried that :) unfortunately, nothing happens

KieranLafferty commented 11 years ago

try performing [noteView reloadDataAnimated:NO]; after the change

KieranLafferty commented 11 years ago

Using a break poing check if the line :

TDListViewController viewController = (TDListViewController *)[self noteView:self viewControllerForRowAtIndexPath:path];

is actually returning a TDListViewController and not a UINavigationController

KieranLafferty commented 11 years ago

Just a note as well, in the code:

NSIndexPath path = [self indexPathForControllerCard:controllerCard]; TDListViewController viewController = (TDListViewController *)[self noteView:self viewControllerForRowAtIndexPath:path]; viewController.navigationController.navigationItem.leftBarButtonItem= nil;

you need a * after NSIndexPath and TDListViewController

leoru commented 11 years ago

i understand

leoru commented 11 years ago

TDListViewController viewController = (TDListViewController *)[self noteView:self viewControllerForRowAtIndexPath:path];

it's return me right TDListViewController with right variables

leoru commented 11 years ago

try performing [noteView reloadDataAnimated:NO]; after the change if (toState == KLControllerCardStateDefault) { NSIndexPath path = [self indexPathForControllerCard:controllerCard]; TDListViewController viewController = (TDListViewController *)[self noteView:self viewControllerForRowAtIndexPath:path]; viewController.navigationController.navigationItem.leftBarButtonItem= nil; viewController.navigationItem.leftBarButtonItem= nil; [self reloadDataAnimated:NO]; }

if i run this code, i have exception:

Terminating app due to uncaught exception 'NSRangeException', reason: '*\ -[_PFArray objectAtIndex:]: index (2147483647) beyond bounds (2)'

KieranLafferty commented 11 years ago

Note you can also get the uiNavigationController reference by simply doing controllerCard.navigationController

leoru commented 11 years ago

Maybe the problem in my

KieranLafferty commented 11 years ago

You need to have * after UIStoryboard and TDListViewController. You are initializign a pointer

KieranLafferty commented 11 years ago

Be sure you understand what the * actually means in the context of assignment

KieranLafferty commented 11 years ago

you must be getting warnings for that no?

leoru commented 11 years ago

I understand, i paste this piece of code from xcode, but in xcode i have * when it's nessesary, but there * are hidden. So strange

KieranLafferty commented 11 years ago

ahhh ok I thought you were just not using them and was wondering how it was even working :P

leoru commented 11 years ago

If I did not have *, my code won't be compiled

leoru commented 11 years ago

I try a dirty hack. i add viewController property to KLControllerCard. @property (nonatomic, strong) UIViewController* viewController;

And in reloadData add: UIViewController* viewController = [self noteView:self viewControllerForRowAtIndexPath:[NSIndexPath indexPathForRow:count inSection:0]];

    UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

    KLControllerCard* noteContainer = [[KLControllerCard alloc] initWithNoteViewController: self
                                                                                navigationController: navigationController
                                                                                               index:count];

// i add this line noteContainer.viewController = viewController;

And now in -(void) noteViewController: (KLNoteViewController) noteViewController didUpdateControllerCard:(KLControllerCard)controllerCard toDisplayState:(KLControllerCardState) toState fromDisplayState:(KLControllerCardState) fromState { if (toState == KLControllerCardStateDefault) { [((TDListViewController *)controllerCard.viewController) updateUI]; }

}

leoru commented 11 years ago

Do you think it looks like a patch to your component? :P