Closed AndrexOfficial closed 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
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
Can you please paste the exact code you used
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 :)
this is my entire code but doesn't work.
@interface KLViewController ()
@end
@implementation KLViewController
(void)viewDidLoad {
// Do any additional setup after loading the view, typically from a nib. [self.view setBackgroundColor: [UIColor colorWithPatternImage:[UIImage imageNamed:@"background-dark-gray-tex.png"]]];
//Initialize the controller data NSString* plistPath = [[NSBundle mainBundle] pathForResource: @"NavigationControllerData" ofType: @"plist"]; // Build the array from the plist //self.viewControllerData = [[NSArray alloc] initWithContentsOfFile:plistPath];
NSMutableArray *myArray = [NSMutableArray array]; //my array with the list of UIViewControllers to set
KLTestViewController *red = [[KLTestViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:red];
NSDictionary *view = [NSDictionary dictionaryWithObjectsAndKeys:nav, @"vc", [NSString stringWithFormat:@"Home"], @"title", nil]; [vcs addObject:view];
[self.completeMadeUpArrayName addObject: red];
[super viewDidLoad];
}
(UIViewController )noteView:(KLNoteViewController)noteView viewControllerForRowAtIndexPath:(NSIndexPath )indexPath { //Get the relevant data for the navigation controller NSDictionary navDict = [self.viewControllerData objectAtIndex: indexPath.row];
//Initialize a blank uiviewcontroller for display purposes UIStoryboard *st = [UIStoryboard storyboardWithName:[[NSBundle mainBundle].infoDictionary objectForKey:@"UIMainStoryboardFile"] bundle:[NSBundle mainBundle]];
KLCustomViewController* viewController = [st instantiateViewControllerWithIdentifier:@"RootViewController"]; [viewController setInfo: navDict];
//Return the custom view controller return viewController; }
-(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
What error are you getting in the console
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
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
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;
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