UA-17470720-3

Jump to content


Photo
- - - - -

Cell resizes but then fixes


  • Please log in to reply
55 replies to this topic

#41 Karl1348790294

Karl1348790294

    Experienced Member

  • STV 5.0 Std
  • PipPipPipPip
  • 90 posts
Reputation: 6
Good

Posted 28 October 2015 - 09:46 AM

I've looked at this further, and I am sure that detailModelConfigured is not being called.

I have put the following code into the viewDidLoad for my index view.

The detail is still being shown in the left hand pane of the splitview.

 

 

        self.tableViewModel.detailViewController = nil
        
        self.tableViewModel.sectionActions.detailModelConfigured = {
            
            (section, detailModel, indexPath) in

            print("detailModelConfigured has been called")
            
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            
            let detailNavController = storyboard.instantiateViewControllerWithIdentifier("GroupDetailNC") as! UINavigationController
            self.splitViewController!.viewControllers[1] = detailNavController
            
            let detailController = detailNavController.viewControllers.first
            detailModel.detailViewController = detailController
        }
        

 

 



#42 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 29 October 2015 - 10:55 AM

Hi Karl,

 

I think I now know why it's not being called, as it seems that the detail model is in an already existing view controller on your Storyboard. I'll PM you an updated beta version of STV that should fix that. Would you kindly confirm if it now works for you?



#43 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 29 October 2015 - 04:50 PM

Hi Karl,

 

Thanks again for confirming detailModelConfigured is now called with the beta. I am not sure what exactly is the problem with your code, but adding the following code to our bundled TasksApp MasterViewController.m seems to be working fine on an iPad:

 

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
     UIViewController *detailViewController = nil;
     if(self.tableViewModel.detailViewController)
     {
         detailViewController = self.tableViewModel.detailViewController;
         self.tableViewModel.detailViewController = nil;
         
         self.tableViewModel.sectionActions.detailModelConfigured = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
         {
             UIViewController *rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
             if([rootViewController isKindOfClass:[UISplitViewController class]])
             {
                 UISplitViewController *splitViewController = (UISplitViewController *)rootViewController;
                 if(!splitViewController.collapsed)
                     detailModel.detailViewController = detailViewController;
             }
         };
     }
    
}

 

Please let me know if the above is working for you.



#44 Karl1348790294

Karl1348790294

    Experienced Member

  • STV 5.0 Std
  • PipPipPipPip
  • 90 posts
Reputation: 6
Good

Posted 30 October 2015 - 05:58 AM

No, I am afraid this doesn't do anything for me at all.

 

I didn't really expect it to. The line "detailViewController = self.tableViewModel.detailViewController;" seems to assume that the tableViewModel knows where the detail view is - which is the very thing I am trying to establish.

 

STV seems to work fine in the left hand pane of the split view, but not in the right. If i try to put something in the right pane of the split, that works perfectly well in the left pane, then it no longer works.


I think my problem must be that I do not really understand the architecture of STV.
 

karl



#45 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 30 October 2015 - 10:06 AM

If you wish, I could have a look at your project or a simplified sample (even better). Just PM me a link to the zipped file.

#46 Karl1348790294

Karl1348790294

    Experienced Member

  • STV 5.0 Std
  • PipPipPipPip
  • 90 posts
Reputation: 6
Good

Posted 30 October 2015 - 11:31 AM

Thank you Tarek, I really appreciate your help.

Unfortunately, as of this afternoon I am having other problems with the linker and "libsqlite3"

so the project is in no state for me to do anything else with until I have sorted that out.

 

Thanks anyway

karl



#47 Karl1348790294

Karl1348790294

    Experienced Member

  • STV 5.0 Std
  • PipPipPipPip
  • 90 posts
Reputation: 6
Good

Posted 01 November 2015 - 12:20 PM

Just in case anyone else reads this, I solved the problem with linker error connected to 'libsqlite3.dylib' by removing 'libsqlite3.dylib' from my project and adding 'libsqlite3.tbd' in the Linked Frameworks and Libraries section of the General project settings.


  • Tarek likes this

#48 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 03 November 2015 - 10:00 AM

Hi Karl,

 

Thanks for attaching your project. 

 

What I see here is that you've already generated the entire view controller UI in the storyboard, so using 'detailModelConfigured' to tell STV where to present the view controller will have no effect, since your Storyboard already specifies that. The easiest way here is to tell STV that you want to present the detailViewController yourself by implementing sectionActions.customPresentDetailModel. Here is what I did to get this desired result in your project:

 

a. Completely removed sectionActions.detailModelConfigured from StudentMasterViewController.swift

b. Added the following code instead:

    self.tableViewModel.sectionActions.customPresentDetailModel =
        {
            (section, detailModel, indexPath) in
            
            let detailViewController = detailModel.viewController
            self.splitViewController!.viewControllers[1] = detailViewController
        }

 

Please note that you should probably also restore your original LogoViewController when StudentMasterViewController disappears. Code should look something like this:

override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
        
        let logoViewController = storyboard!.instantiateViewControllerWithIdentifier("LogoViewController")  // assuming you've assigned this ID in IB
        self.splitViewController!.viewControllers[1] = logoViewController
    }

 

Hope this helps.


  • wizgod likes this

#49 Karl1348790294

Karl1348790294

    Experienced Member

  • STV 5.0 Std
  • PipPipPipPip
  • 90 posts
Reputation: 6
Good

Posted 03 November 2015 - 10:57 AM

That's brilliant!

Thank you so much

karl



#50 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 136
Popular

Posted 03 November 2015 - 11:28 AM

Hi Karl and Tarek,

 

I've been following this thread with interest as I've also been struggling for a while with UISplitViewController and presenting STV detailViews either side of the split as required.

 

I made the changes to Karl's project as above, but I'm still seeing some issues, in no particular order:

 

On iPhone or iPhonePlus in portrait the LogoViewController is the first presented view without any navigation to go anywhere else.

 

On an iPhonePlus in landscape Students > Administration is on the left and the StudentDetailViewController is on the right, that looks OK. However clicking the add button, the + for the Students results in StudentDetailViewController still on the right being used as the adding UI, but it doesn't have a Done button of any sort to actually add the Student, although selecting another Student seems to save the newly added one. Also if I rotate the device back to portrait I get a crash

 

fatal error: Array index out of range

 

on the line

self.splitViewController!.viewControllers[1] = logoViewController

 

from the viewWillDisappear method (are they functions now in Swift?).

 

 

I had the most success getting the UISplitViewController working if I took over delegate duties and used the STV customPresentDetailModel to present every detailViewController via my UISplitViewControllerDelegate as required. There are still issues with my implementation, but I might crack it one of these days! 


Cheers,

Dave

www.dgapps.ie

#51 Karl1348790294

Karl1348790294

    Experienced Member

  • STV 5.0 Std
  • PipPipPipPip
  • 90 posts
Reputation: 6
Good

Posted 03 November 2015 - 11:35 AM

Hi Dave,

 

With regard to the logo being shown without any navigation etc. on the iPhone, that's because the project i uploaded was much cut down and the code to handle that was removed for simplicity.

 

With regard to the new record being displayed on the right hand side, i guess some code could be added to determine if the record to be displayed is new or not, and thus adapt the presentation accordingly. If you check the value of indexPath.row when it is passed into self.tableViewModel.sectionActions.customPresentDetailModel then if it is NSNotFound then the record is new.

 

I'd did have to week Tarek's code a little to add a navigation controller for the 'Cancel' and 'Done' buttons to appear.

 

This is what i did:

 

        
        self.tableViewModel.sectionActions.customPresentDetailModel = {
            
            (section, detailModel, indexPath) in
            
            let detailNavController = self.storyboard!.instantiateViewControllerWithIdentifier("StudentDetailNC") as! UINavigationController
            
            let detailViewController = detailModel.viewController
            detailNavController.viewControllers[0] = detailViewController
            
            self.splitViewController!.viewControllers[1] = detailNavController
        }

 

Which works fine, I still need to ensure that the buttons work as expected, I am manually dismissing the view by implementing the following  and using them to display my logo view

 

override func cancelButtonAction() {

}

override func doneButtonAction() {

}

 

 

thanks

karl


Edited by Karl1348790294, 03 November 2015 - 12:57 PM.


#52 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 136
Popular

Posted 04 November 2015 - 01:47 AM

Hi Karl,

 

Yes I'm aware of NSNotFound for new items, I was just hoping that STV was going to automagically handle all of that for us!

 

With your code above I still have the crash in viewDidDisappear at 

 

self.splitViewController!.viewControllers[1] = logoViewController

 

 

Also, if I remark out that line, start the app in landscape on a iPhone6Plus, select Students and then select a student, then rotate back to portrait, tap Cancel and then select Students again, and select a student again,  I get a crash in customPresentDetailModel at 

 

self.splitViewController!.viewControllers[1] = detailNavController

 

 

fatal error: Array index out of range

 
 
 
(This is all in the simulator. Rotation of the simulator in Xcode 6.x was more or less simultaneous. Now in Xcode 7 with the  iOS 9.1 simulator rotating a iPhone6sPlus device takes between 5 and 10 seconds! Is that just me? Or are other people seeing that as well? Time for a new laptop maybe?)

Cheers,

Dave

www.dgapps.ie

#53 Karl1348790294

Karl1348790294

    Experienced Member

  • STV 5.0 Std
  • PipPipPipPip
  • 90 posts
Reputation: 6
Good

Posted 04 November 2015 - 03:14 AM

I suspect that will be because of the cut down project I had removal the code that deals with collapsing and expanding primary/secondary view controllers. I don't think it is an STV problem.
Karl

#54 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 545 posts
  • LocationIreland
Reputation: 136
Popular

Posted 04 November 2015 - 09:53 AM

Hi Karl,

 

 

As I said I've been struggling for a while with UISplitViewController and presenting STV detailViews either side of the split as required.

 

So do you take over delegate duties for the UISplitViewController? Or is STV still the delegate?

 

Can you share some code that does work in all orientations on all devices for all states of the app?


Cheers,

Dave

www.dgapps.ie

#55 Karl1348790294

Karl1348790294

    Experienced Member

  • STV 5.0 Std
  • PipPipPipPip
  • 90 posts
Reputation: 6
Good

Posted 04 November 2015 - 01:22 PM

I handle some of the split view stuff myself. In the app delegate i implement:

 

func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController:UIViewController, ontoPrimaryViewController primaryViewController:UIViewController) -> Bool {
}

and 

func splitViewController(splitViewController: UISplitViewController, separateSecondaryViewControllerFromPrimaryViewController primaryViewController: UIViewController) -> UIViewController? {
}

 

And when i create detail views I make sure i set leftBarButtonItem and leftItemsSupplementBackButton but that is about it.

 

karl



#56 Karl1348790294

Karl1348790294

    Experienced Member

  • STV 5.0 Std
  • PipPipPipPip
  • 90 posts
Reputation: 6
Good

Posted 04 November 2015 - 01:24 PM

For example (an this is probably not very good code) : - but this isn't really about STV anymore

   // MARK: - Split view

    func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController:UIViewController, ontoPrimaryViewController primaryViewController:UIViewController) -> Bool {
        //printTrace()
        
        let nc = primaryViewController as! UINavigationController
        let menuVC = nc.viewControllers.first as! MenuViewController
        menuVC.showAbout = false
        menuVC.tableView.reloadData()
        
        let svc = secondaryViewController as! UINavigationController
        let vc = svc.viewControllers.first

        if vc!.isKindOfClass(LogoViewController) {
            return true
        }
        if vc!.isKindOfClass(AboutViewController) {
            return true
        }
        return false
    }
    
    func splitViewController(splitViewController: UISplitViewController, separateSecondaryViewControllerFromPrimaryViewController primaryViewController: UIViewController) -> UIViewController? {
        //printTrace()

        let nc = primaryViewController as! UINavigationController
        let menuVC = nc.viewControllers.first as! MenuViewController
        menuVC.showAbout = true
        menuVC.tableView.reloadData()
        
        let pvc = primaryViewController as! UINavigationController
        let vc = pvc.viewControllers.last
        
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        
        let lnc = storyboard.instantiateViewControllerWithIdentifier("LogoNavigationController") as! UINavigationController
        lnc.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem()
        lnc.topViewController!.navigationItem.leftItemsSupplementBackButton = true
        
        let anc = storyboard.instantiateViewControllerWithIdentifier("AboutNavigationController") as! UINavigationController
        anc.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem()
        anc.topViewController!.navigationItem.leftItemsSupplementBackButton = true
        
        if vc!.isKindOfClass(MenuViewController) {
            (anc.topViewController! as! AboutViewController).pdf = "About"
            return anc
        }
        if vc!.isKindOfClass(CoursesViewController)  {
            (anc.topViewController! as! AboutViewController).pdf = "About Courses"
            return anc
        }
        if vc!.isKindOfClass(CoursesDetailViewController)  {
            (anc.topViewController! as! AboutViewController).pdf = "About Courses"
            return anc
        }
        if vc!.isKindOfClass(StudiesViewController)  {
            (anc.topViewController! as! AboutViewController).pdf = "About Studies"
            return anc
        }
        if vc!.isKindOfClass(StudiesDetailViewController)  {
            (anc.topViewController! as! AboutViewController).pdf = "About Studies"
            return anc
        }
        if vc!.isKindOfClass(WorksheetsViewController)  {
            (anc.topViewController! as! AboutViewController).pdf = "About Worksheets"
            return anc
        }
        if vc!.isKindOfClass(WorksheetsDetailViewController)  {
            (anc.topViewController! as! AboutViewController).pdf = "About Worksheets"
            return anc
        }

        return vc
    }
}

Edited by Karl1348790294, 04 November 2015 - 01:25 PM.

  • Tarek likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users