Unfortunately the search didn't help me out... I have the following problem: I have three UItableviews (ViewController1, ViewController2 and Viewcontroller3) which I embedded in a simple PageViewController Screenshot of storyboard ( I can't insert any pictures here yet :/).
In order to display the three ViewControllers I put them into an array in my viewdidload in my PageViewController.m (custom class for the PageViewController), so I didn't use a ViewController as a Container to lod the other ViewControllers into:
-(void)viewDidLoad
{
[super viewDidLoad];
self.delegate = self;
self.dataSource = self;
UIViewController *p1 = [self.storyboard
instantiateViewControllerWithIdentifier:#"TableView1"];
UIViewController *p2 = [self.storyboard
instantiateViewControllerWithIdentifier:#"TableView2"];
UIViewController *p3 = [self.storyboard
instantiateViewControllerWithIdentifier:#"TableView3"];
myViewControllers = #[p1,p2,p3];
I can pick which viewcontroller I start with and either
- go forwards(direction:UIPageViewControllerNavigation**DirectionForward**):
[self setViewControllers:#[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
NSLog(#"loaded!");
}
or pick the last on and go backwards (UIPageViewControllerNavigation**DirectionReverse**):
[self setViewControllers:#[p3]
direction:UIPageViewControllerNavigationDirectionReverse
animated:NO completion:nil];
However, I've been trying to figure out how to start with ViewController2 and have Viewcontroller1 on its left and ViewController3 on the right (cp. Screenshot)
Any suggestions or code snippets would be hugely appreciated!
And here's the entire code:
#import "StartScreenPageViewController.h"
#interface StartScreenPageViewController ()
#end
#implementation StartScreenPageViewController
{
NSArray *myViewControllers;
}
-(void)viewDidLoad
{
[super viewDidLoad];
self.delegate = self;
self.dataSource = self;
UIViewController *p1 = [self.storyboard
instantiateViewControllerWithIdentifier:#"1"];
UIViewController *p2 = [self.storyboard
instantiateViewControllerWithIdentifier:#"2"];
UIViewController *p3 = [self.storyboard
instantiateViewControllerWithIdentifier:#"3"];
myViewControllers = #[p1,p2,p3];
[self setViewControllers:#[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
NSLog(#"loaded!");
}
-(UIViewController *)viewControllerAtIndex:(NSUInteger)index
{
return myViewControllers[index];
}
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [myViewControllers indexOfObject:viewController];
--currentIndex;
currentIndex = currentIndex % (myViewControllers.count);
return [myViewControllers objectAtIndex:currentIndex];
}
-(UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [myViewControllers indexOfObject:viewController];
++currentIndex;
currentIndex = currentIndex % (myViewControllers.count);
return [myViewControllers objectAtIndex:currentIndex];
}
-(NSInteger)presentationCountForPageViewController:
(UIPageViewController *)pageViewController
{
return myViewControllers.count;
}
-(NSInteger)presentationIndexForPageViewController:
(UIPageViewController *)pageViewController
{
return 0;
}
#end
You should be able to set the initial view controller in viewDidLoad. You're already doing it, but you're setting it to the first view controller:
[self setViewControllers:#[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
I think you should just be able to change this to:
[self setViewControllers:#[p2]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
Then just make sure your pageViewController:viewControllerAfterViewController and pageViewController:viewControllerBeforeViewController methods handle iterating up and down the data source per your desired functionality.
Related
#interface MyCustomView() #end
#implementation MyCustomView
- (instancetype)init {
self = [[[MyClass bundle] loadNibNamed:kOverlayNib owner:self options:nil] firstObject];
self.layer.cornerRadius = 10;
self.translatesAutoresizingMaskIntoConstraints = NO;
self.userInteractionEnabled = YES;
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(handleSingleTap:)];
[singleFingerTap setNumberOfTapsRequired:1];
[singleFingerTap setNumberOfTouchesRequired:1];
[self addGestureRecognizer:singleFingerTap];
return self; }
//The event handling method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
NSLog(#"Tappedddddddddd");
}
I have added Tap Gesture Recognizer to my kOverlayNib.xib but for some reason i can not get any response.. It is not working at all..
you missed some things..
#interface MyCustomView() <UIGestureRecognizerDelegate> #end or anywhere you want to write.
singleFingerTap.delegate = self;
- (BOOL)gestureRecognizer:(UIGestureRecognizer )gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer)otherGestureRecognizer { return YES; }
Now you can run your code. it works.
so I'm pretty new to Obj-C and have tried looking at sample code and other online resources to answer my question, but I can't seem to find anything that really helps. Essentially what I'm trying to do is to add multiple UIViewControllers that I created in Storyboard to a UIPageViewController - the first place I looked to for help was Xcode itself by using a template of a PageBased application. That actually helped quite a lot and I got a PageController up and running. Then I turned to online resources but most (if not all of them) use a single viewController (like this). Then I turned to StackOverflow and found the following - How to implement UIPageViewController that utilizes multiple ViewControllers.
The above resources got me this far:
In PageViewController.h:
#import <UIKit/UIKit.h>
#interface PageViewController : UIPageViewController <UIPageViewControllerDataSource>
#end
In PageViewController.m:
#import "PageViewController.h"
#interface PageViewController ()
#end
#implementation PageViewController {
NSArray *viewControllers;
UIViewController *first;
UIViewController *second;
UIViewController *third;
UIViewController *fourth;
UIViewController *fifth;
}
- (UIViewController *)first {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
first = [sb instantiateViewControllerWithIdentifier:#"1"];
return first;
}
- (UIViewController *)second {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
second = [sb instantiateViewControllerWithIdentifier:#"2"];
return second;
}
- (UIViewController *)third {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
third = [sb instantiateViewControllerWithIdentifier:#"3"];
return third;
}
- (UIViewController *)fourth {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
fourth = [sb instantiateViewControllerWithIdentifier:#"4"];
return fourth;
}
- (UIViewController *)fifth {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
fifth = [sb instantiateViewControllerWithIdentifier:#"5"];
return fifth;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.dataSource = self;
// Aggancio il view controller iniziale.
[self setViewControllers:#[self.first]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
UIViewController *nextViewController = nil;
if (viewController == self.first) {
nextViewController = self.second;
}
if (viewController == self.second) {
nextViewController = self.third;
}
if (viewController == self.third) {
nextViewController = self.fourth;
}
if (viewController == fourth) {
nextViewController = self.fifth;
}
return nextViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
UIViewController *prevViewController = nil;
if (viewController == self.fifth) {
prevViewController = self.fourth;
}
if (viewController == self.fourth) {
prevViewController = self.third;
}
if (viewController == self.third) {
prevViewController = self.second;
}
if (viewController == self.second) {
prevViewController = self.first;
}
return prevViewController;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
All this code does is load the first view controller which is now swipe-able, but doesn't actually swipe towards anything - why is this?. What am I doing wrong? The aforementioned resources used titles and pages to create views and I really don't know how to go about this. Would anyone mind guiding me or nudging me in the correct direction? Any help would be greatly appreciated. Thanks!
Here is the fully working code if anyone is interested. Took me a while to get it right, but eventually this worked perfectly!
#import "PageViewController.h"
#interface PageViewController ()
#property (nonatomic, retain) UIViewController *first;
#property (nonatomic, retain) UIViewController *second;
#property (nonatomic, retain) UIViewController *third;
#property (nonatomic, retain) UIViewController *fourth;
#property (nonatomic, retain) UIViewController *fifth;
#end
#implementation PageViewController {
NSArray *viewControllers;
}
- (UIViewController *)first {
if (!_first) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
_first = [sb instantiateViewControllerWithIdentifier:#"1"];
}
return _first;
}
- (UIViewController *)second {
if (!_second) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
_second = [sb instantiateViewControllerWithIdentifier:#"2"];
}
return _second;
}
- (UIViewController *)third {
if (!_third) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
_third = [sb instantiateViewControllerWithIdentifier:#"3"];
}
return _third;
}
- (UIViewController *)fourth {
if (!_fourth) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
_fourth = [sb instantiateViewControllerWithIdentifier:#"4"];
}
return _fourth;
}
- (UIViewController *)fifth {
if (!_fifth) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Secondary" bundle:nil];
_fifth = [sb instantiateViewControllerWithIdentifier:#"5"];
}
return _fifth;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.dataSource = self;
// Aggancio il view controller iniziale.
[self setViewControllers:#[self.first]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
UIViewController *nextViewController = nil;
if (viewController == self.first) {
nextViewController = self.second;
}
if (viewController == self.second) {
nextViewController = self.third;
}
if (viewController == self.third) {
nextViewController = self.fourth;
}
if (viewController == self.fourth) {
nextViewController = self.fifth;
}
return nextViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
UIViewController *prevViewController = nil;
if (viewController == self.fifth) {
prevViewController = self.fourth;
}
if (viewController == self.fourth) {
prevViewController = self.third;
}
if (viewController == self.third) {
prevViewController = self.second;
}
if (viewController == self.second) {
prevViewController = self.first;
}
return prevViewController;
}
#end
This is old, but it helped me out a lot. For some reason your code had some problems for me, and I wasn't using storyboard. For anyone's future reference, this is the code I'm using that works:
#import "PageController.h"
#import "SeasonTixViewController.h"
#import "SeasonTicketPricesViewController.h"
#import "ArenaLayoutSeasonTixViewController.h"
#interface PageController ()
#property (nonatomic, retain) UIViewController *first;
#property (nonatomic, retain) UIViewController *second;
#property (nonatomic, retain) UIViewController *third;
#end
#implementation PageController {
NSArray *viewControllers;
}
- (UIViewController *)first {
if (!_first) {
SeasonTixViewController *first = [[SeasonTixViewController alloc] init];
_first = first;
}
return _first;
}
- (UIViewController *)second {
if (!_second) {
SeasonTicketPricesViewController *second = [[SeasonTicketPricesViewController alloc] init];
_second = second;
}
return _second;
}
- (UIViewController *)third {
if (!_third) {
ArenaLayoutSeasonTixViewController *third = [[ArenaLayoutSeasonTixViewController alloc] init];
_third = third;
}
return _third;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
[[self.pageController view] setFrame:self.view.bounds];
self.pageController.dataSource = self;
[self.pageController setViewControllers:#[self.first]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
UIViewController *nextViewController = nil;
if (viewController == self.first) {
nextViewController = self.second;
}
if (viewController == self.second) {
nextViewController = self.third;
}
return nextViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
UIViewController *prevViewController = nil;
if (viewController == self.third) {
prevViewController = self.second;
}
if (viewController == self.second) {
prevViewController = self.first;
}
return prevViewController;
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
// The number of items reflected in the page indicator.
return 3;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
// The selected item reflected in the page indicator.
return 0;
}
#end
I've created a new project with two ViewControllers and imported a class that pushes ViewController from right to left instead LTR but can't manage to use it. I can see that pushViewController inside UIRightToLeft.m is not being called and I don't understand why.
My main goal is to get that working with RTL aniamtion.
#import "UIRightToLeft.h"
#implementation UIRightToLeft
- (id)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super initWithRootViewController:rootViewController];
if (!self)
return nil;
return self;
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
NSLog(#"pushViewController");
// Add the viewController and a fake controller without animation. Then pop the fake controller with animation.
UIViewController *fakeController = [[UIViewController alloc] init] ;
[super setViewControllers:[[self viewControllers] arrayByAddingObjectsFromArray:[NSArray arrayWithObjects:viewController, fakeController, nil]] animated:NO];
[super popViewControllerAnimated:animated];
}
- (void)popViewControllerAnimatedStep2:(UIViewController *)viewController
{
// Push the new top controller with animation
[super pushViewController:viewController animated:YES];
// Remove the view that should have been popped
NSMutableArray *arr = [NSMutableArray arrayWithArray:[self viewControllers]];
[arr removeObjectAtIndex:[[self viewControllers] count]-2];
[super setViewControllers:[NSArray arrayWithArray:arr] animated:NO];
}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
NSLog(#"popViewControllerAnimated");
if (animated)
{
// Save the controller that should be on top after this pop operation
UIViewController *newTopController = [[self viewControllers] objectAtIndex:[[self viewControllers] count]-2];
// Remove it from the stack. Leave the view that should be popped on top
NSMutableArray *arr = [NSMutableArray arrayWithArray:[self viewControllers]];
[arr removeObjectAtIndex:[[self viewControllers] count]-2];
[super setViewControllers:[NSArray arrayWithArray:arr] animated:NO];
// Schedule the next step
[self performSelector:#selector(popViewControllerAnimatedStep2:) withObject:newTopController afterDelay:0];
return [arr objectAtIndex:[arr count]-1];
}
return [super popViewControllerAnimated:NO];
}
#end
ViewController.m:
#import "ViewController.h"
#import "UIRightToLeft.h"
#import "SecondViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)pressMe:(UIButton *)sender {
SecondViewController *next = [[SecondViewController alloc]init];
[self.navigationController pushViewController:next animated:YES];
}
#end
ViewController.h:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
- (IBAction)pressMe:(UIButton *)sender;
#end
(In my ViewController there's only one button draged to the second ViewController with push)
After looking at your error log I think you actually need to have your navigation controller subclass UIRightToLeft.
If you are using a Storyboard, select your navigation controller and set Custom Class to UIRightToLeft.
Yes, It might be a duplicate question of this. But since it didn't get an answer, I will be more specific on the case and code:
I have 3 involved UIViewControllers:
WelcomeView - the first one
TakePhotoViewController - the second one who is delegate of the OverlayviewController
OverlayViewController - custom view for the camera.
Scenario:
User enter WelcomeView and clicks on a button to be transfered with segue to TakeView.
UIImageViewController is being opened to take a photo.
The user clicks on cancel button - didCancelCamera method in TakePhotoViewController is being invoked and he returns to WelcomeView
The user leaves the app.
The user re-opens the app and perform step 1 again.
THE IMAGE PICKER IS NOT BEING OPENED. I COULD TAKE A PHOTO AND IT'S OK - BUT THE USER CAN'T SEE WHAT HE IS TAKING.
OverlayViewController.h
#interface OverlayViewController : BaseViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
#property (nonatomic,weak) id<OverlayViewControllerDelegate> delegate;
#property (nonatomic,retain) UIImagePickerController *imagePickerController;
#end
OverlayViewController.m:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.delegate = self;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
}
- (IBAction)takePicture:(id)sender {
[self.imagePickerController takePicture];
}
- (IBAction)cancelImagePicker:(id)sender {
[self.delegate didCancelCamera];
}
- (void) setupImagePicker:(UIImagePickerControllerSourceType) sourceType
{
self.imagePickerController.sourceType = sourceType;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
self.imagePickerController.showsCameraControls = NO;
if ([[self.imagePickerController.cameraOverlayView subviews] count] ==0)
{
CGRect overlayViewFrame = self.imagePickerController.cameraOverlayView.frame;
CGRect newFrame = CGRectMake(0.0, CGRectGetHeight(overlayViewFrame)-self.view.frame.size.height-10.0, CGRectGetWidth(overlayViewFrame), self.view.frame.size.height + 10.0);
self.view.frame = newFrame;
[self.imagePickerController.cameraOverlayView addSubview:self.view];
}
}
}
- (void)finishAndUpdate
{
[NSThread detachNewThreadSelector:#selector(threadStartAnimating:) toTarget:self withObject:nil];
[self.delegate didFinishWithCamera]; // tell our delegate we are done with the camera
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self finishAndUpdate];
}
TakePhotoViewController.h
#interface TakePhotoViewController : BaseViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate,OverlayViewControllerDelegate>
#property (nonatomic, retain) OverlayViewController *overlayViewController;
#end
TakePhotoViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
// Insert the overlay
self.overlayViewController = (OverlayViewController *)[sb instantiateViewControllerWithIdentifier:#"Overlay"];
self.overlayViewController.delegate = self;
}
- (void)viewDidUnload
{
self.overlayViewController = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (void)openImagePicker {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
[self showImagePicker:UIImagePickerControllerSourceTypeCamera];
}
else{
[self showImagePicker:UIImagePickerControllerSourceTypePhotoLibrary];
}
}
- (void)viewDidAppear:(BOOL)animated{
if (appDelegate.shouldOpenPicker){
[self openImagePicker];
}
}
- (void)showImagePicker:(UIImagePickerControllerSourceType)sourceType
{
if ([UIImagePickerController isSourceTypeAvailable:sourceType])
{
[self.overlayViewController setupImagePicker:sourceType];
[self presentViewController:self.overlayViewController.imagePickerController animated:YES completion:nil];
}
}
-(void)didCancelCamera{
[[self.overlayViewController.imagePickerController presentingViewController] dismissViewControllerAnimated:NO completion:^ {
[self performSegueWithIdentifier:#"fromTakeToWelcome" sender:self];
}];
}
I found the bug.
The method
-(void)didCancelCamera from TakePhotoViewController is being called when the user clicks on - (IBAction)cancelImagePicker:(id)sender in OverlayViewController.
However, somehow the code in didCancelCamera causes viewDidAppear method of TakePhotoViewController to be invoked again and reopen the image picker.
I have no idea why
[[self.overlayViewController.imagePickerController presentingViewController] dismissViewControllerAnimated:NO completion:^ {
[self performSegueWithIdentifier:#"fromTakeToWelcome" sender:self];
}];
causes the viewDidAppear method of that view (TakePhoto) being recalled again.
Hope that it will help someone
when I click the popover button in my splitviewcontroller, I receive the message: message sent to deallocated instance 0x6a66ca0
I already found out that this instance has to be the detailviewcontroller I allocate and init. So far so good. But I don't see the problem while the whole thing is not working.
First of all the AppDelegate where I create the Splitview:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// TestViews for SplitViewController
// TestView1 *test1 = [[TestView1 alloc] initWithNibName:#"TestView1" bundle:nil];
// TableView as RootViewController for the Left Hand Pane
RootViewTableViewController *rootViewTableViewController = [[RootViewTableViewController alloc] initWithNibName:#"RootViewTableView" bundle:nil];
UINavigationController *rootNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewTableViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:rootNavigationController,detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
return YES;
}
First I was thinking the code line self.splitviewcontroller.delegate = detailviewcontroller; could be the problem..... but the whole app starts up perfectly. only when i click the button this prob appears.
the RootViewController is this ( I omitted the standard tableview delegate methods for clarity)
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Set Title of the TableView for the RootViewController
self.title = #"Notarzteinsatzprotokoll";
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
}
NSLog(#"INIT %p", self);
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
}
and the detail view controller:
#pragma mark -
#pragma mark Managing the Detail Item
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view
[self configureView];
}
if (self.rootPopoverController != nil) {
[self.rootPopoverController dismissPopoverAnimated:YES];
}
}
- (void)configureView
{
// Update the user interface for the detail item
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setTitle:#"Notarzteinsatzprotokoll"];
[self configureView];
}
#pragma mark -
#pragma mark Rotation Support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return YES;
}
#pragma mark -
#pragma mark SplitView
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc {
barButtonItem.title = #"Master";
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
self.rootPopoverController = pc;
}
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.rootPopoverController = nil;
}
I don't see the point the program flow where the detailviewcontroller objects is released and something else tries to send a message... do I have to interchange some code lines?
Thank you!
Sebastian
#end
the error should tell you what message is being sent to a deallocated instance. Not sure exactly what the issue is, is it a setTitle: message being sent to the left bar button item?
In splitViewController:willShowViewController: you set the left bar button item to nil (which will dealloc it) and in splitViewController:willHideViewController: you attempt to changed its title, which could be your problem.