vmodena / ICSDrawerController

ICSDrawerController is a left-side drawer controller for iPhone (iOS 7 or later).
MIT License
253 stars 73 forks source link

ReplaceCenterView #4

Open haxinc opened 10 years ago

haxinc commented 10 years ago

Hi,

How could I use the self.drawer replacecenterviewcontroller to use it instead of self.navigationController pushView

I used this code: TagsViewController *x = [[TagsViewController alloc] initWithStyle:UITableViewStylePlain];

[self.drawer replaceCenterViewControllerWithViewController:x];

it shows this error

Thanks , since [self.drawer open] it doesn't work with UInavigationController

vmodena commented 10 years ago

Hi,

the methods

- (void)reloadCenterViewControllerUsingBlock:(void (^)(void))reloadBlock;

- (void)replaceCenterViewControllerWithViewController:(UIViewController<ICSDrawerControllerChild, ICSDrawerControllerPresenting> *)viewController;

are both meant to be called when the drawer is open: from the failing NSParameterAssert error message you posted, it seems you are calling this method when the drawer is not open.

To use a UINavigationController as your center view controller, you could:

  1. subclass UINavigationController (which according to the documentation is possible starting from iOS 6), adopt the <ICSDrawerControllerChild> protocol and implement the required drawer property
  2. implement an openDrawer method that calls [self.drawer open]
  3. in the navigation controller's root view controller, let the open button trigger a call to the parent view controller's openDrawer method
RenChenLD commented 10 years ago

I have the same problem. I try to add some views instead of changing background colors. Here are my codes that are followed your annotations.

[self.drawer reloadCenterViewControllerUsingBlock:^(){ if (indexPath.row == 0) { userViewController uV = [[userViewController alloc]init]; [center.view addSubview:uV.view]; }else if (indexPath.row == 1) { cameraViewController cV = [[cameraViewController alloc]init]; [center.view addSubview:cV.view]; }else if (indexPath.row == 2) { localViewController *lV = [[localViewController alloc]init]; [center.view addSubview:lV.view]; } [self.drawer replaceCenterViewControllerWithViewController:center]; }];

When the project runs to the codes about replaceCenterViewControllerWithViewController, it broke down. libc++abi.dylib: terminating with uncaught exception of type NSException

vmodena commented 10 years ago

To replace the current center view controller with a different one, you need to call only replaceCenterViewControllerWithViewController:

YourNewCenterViewController *vc = [[YourNewCenterViewController alloc] init];
[self.drawer replaceCenterViewControllerWithViewController:vc];

(The method reloadCenterViewControllerUsingBlock: is intended to be called when you want to update the current center view controller state (e.g. reload its data))

RenChenLD commented 10 years ago

Thanks, it works. : ) 在 2014年4月29日,下午10:14,vmodena notifications@github.com 写道:

To replace the current center view controller with a different one, you need to call only replaceCenterViewControllerWithViewController:

YourNewCenterViewController *vc = [[YourNewCenterViewController alloc] init]; [self.drawer replaceCenterViewControllerWithViewController:vc]; (The method reloadCenterViewControllerUsingBlock: is intended to be called when you want to update the current center view controller state (e.g. reload its data))

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

hiren245 commented 8 years ago

I have tried as above You mentioned like, YourNewCenterViewController *vc = [[YourNewCenterViewController alloc] init]; [self.drawer replaceCenterViewControllerWithViewController:vc];

but i am getting error as following, 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: self.drawerState == ICSDrawerControllerStateOpen'

Please Help Me Out