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 to set an Array of UIViews just like a menu #2

Closed AndrexOfficial closed 11 years ago

AndrexOfficial commented 11 years ago

How to make an Array of UIViews like a menu, for example on the notebooks tag I would like to bound a view named NotebookViewController. Thanks

KieranLafferty commented 11 years ago

Hey Andrex,

From your naming convention of NotebookViewController i am inclined to believe you are talking about a UIViewController subclass. If this is the case you can easily set this array by performing the following:

Assumption : your array of NotebookViewControllers is called myArray

AndrexOfficial commented 11 years ago

Man, I tried everything but gives me errors, in KLViewController i added this but it doesn't work.

I add: (NSInteger)numberOfControllerCardsInNoteView:(KLNoteViewController) noteView { return [myArray count]; } and it gives me an error that myArray doesn't exist, so I set the array with: NSMutableArray vcs = [NSMutableArray array]; but also here it gives me error. Then i add: (UIViewController )noteView:(KLNoteViewController)noteView viewControllerForRowAtIndexPath:(NSIndexPath *)indexPath { return [myArray objectAtIndex: indexPath.row]; } but it give me an error also here and last but not least I can't set a list of xibs (ViewControllers) files to show. Can you write here the entire come to set to View Controllers.

For example: NotebookViewController & NewsViewController.

Thanks

KieranLafferty commented 11 years ago

Can you please paste the exact code you used

KieranLafferty commented 11 years ago

I think you are getting confused by the example project..

I add: (NSInteger)numberOfControllerCardsInNoteView:(KLNoteViewController) noteView { return [myArray count]; } and it gives me an error that myArray doesn't exist, so I set the array with: NSMutableArray vcs = [NSMutableArray array]; but also here it gives me error.

"myArray" as stated was just an example name for an array you might use... you are expected to replace that with whatever you call your array of UIViewController objects.

Then i add: (UIViewController )noteView:(KLNoteViewController)noteView viewControllerForRowAtIndexPath:(NSIndexPath )indexPath { return [myArray objectAtIndex: indexPath.row]; }

Again, if you are returning a newly allocated array called myArray then you will return 0 for (NSInteger)numberOfControllerCardsInNoteView meaning that the * viewControllerForRowAtIndexPath * will not get called.

last but not least I can't set a list of xibs (ViewControllers) files to show.

I suggest you read the Apple documentation on XIB files. They are simply the Interface builder file for setting user interface attributes of the UIViewController. You don't add XIBs to an array you add instances of your UIViewController classes.

i.e if I had a class called KLTestViewController that inherited from UIViewController then I would do the following inside of the viewDidLoad UIViewController method:

KLTestViewController* myFakeController = [[KLTestViewController alloc] initWithNibName: @"KLTestViewController"];

Then I would want to add it to the array (assuming NSMutableArray) so I would do something like

[self.completeMadeUpArrayName addObject: myFakeController];

And do that for each of the view controllers I wished to add to the control.

Can you write here the entire come to set to View Controllers. I dont know what your app is trying to accomplish, or the names of your local variables so the best I can do is the generic sample code I have given in the previous post and this one.

If this is still not enough for you I suggest you download the Github repo again and running it from scratch. Then make small changes, piece by piece to get it working for you. Hopefully this is enough to get you started :)

AndrexOfficial commented 11 years ago

this is my entire code but doesn't work.

import "KLViewController.h"

import "KLCustomViewController.h"

import "KLTestViewController.h"

@interface KLViewController ()

@end

@implementation KLViewController

}

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

NSIndexPath* index = [noteViewController indexPathForControllerCard: controllerCard];
NSDictionary* navDict = [self.viewControllerData objectAtIndex: index.row];

NSLog(@"%@ changed state %ld", [navDict objectForKey:@"title"], toState);

} @end

In viewDidLoad I added the array and a uiviewcontroller to try if it works but to, the app doesn't load the controller and crashes

What can I do?

Sorry for the problems, but someone else could ask this ;DD

KieranLafferty commented 11 years ago

What error are you getting in the console

AndrexOfficial commented 11 years ago

completeMadeUpArrayName was not found in KLViewController.m.

Can you fix the entire come that i paste in order to display a UIViewController between the note card. Did you understand what I want to do?

All the notes you can extract by swiping the finger into your demo project are empty and no editable. I'd like to transform that notes in editable more easily with inserting an UIViewController for each note. A UIViewController is more editable and easy that your stange plist file.

How can we fix this?

Please write the entire working code in order to understand more easily :D

GordonQian commented 11 years ago

hi,friend, How can I get the subcontroller that I add to the notViewController with the delegate method "- (UIViewController )noteView:(KLNoteViewController)noteView viewControllerForRowAtIndexPath:(NSIndexPath *)indexPath"

now , I want to get the controller in the delegate method below, "-(void) controllerCard:(KLControllerCard*)controllerCard didChangeToDisplayState:(KLControllerCardState) toState fromDisplayState:(KLControllerCardState) fromState"

please help me ,thanks

KieranLafferty commented 11 years ago

Hello GordonQian,

I suggest updating to the most recent commit of the project as that delegate method has been updated to make reference to the noteviwcontroller it came from.

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