
Adding a button in an auto-generated detail view
#1
Posted 14 May 2013 - 02:04 PM
#2
Posted 14 May 2013 - 07:23 PM
Hi Stefan,
Luckily there are some good examples already provided. You want to grab on of the detail model blocks to do most of what your question is asking.
To add an extra button to your detail view, here are a couple of examples:
yourArrayOfObjectsSection.sectionActions.detailModelConfigured = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath) {
SCTableViewSection *s = [SCTableViewSection section]; //create new section on they fly
SCTableViewCell *c = [SCTableViewCell cellWithText:@"test cell"]; //create cell on the fly
//give it someting to do
c.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
{
//print something here
};
//add it into the model
[s addCell:c];
[detailModel addSection:s];
};
Here is an example from the header file.
Example:
sectionActions.detailModelConfigured = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
{
SCTableViewSection *customSection = [SCTableViewSection section];
SCCustomCell *customCell = [SCCustomCell cellWithText:@"Custom Cell"];
[customSection addCell:customCell];
[detailModel addSection:customSection];
};
yourArrayOfObjectsSection.sectionActions.detailModelWillPresent = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
{
if (detailModel.viewController.navigationController) {
[detailModel.viewController.navigationController setToolbarHidden:NO];
}
};
- Tarek, David DelMonte and wizgod like this
#3
Posted 14 May 2013 - 10:39 PM
Perfect !
Thanks,
Stefan
#4
Posted 07 February 2015 - 10:41 AM
I'm trying to do this as well. Is there a way to enable the toolbar and button in IB (i.e., set setToolbarHidden:NO) ? I tried a variety of ways and the only thing that worked was dragging a toolbar and button items into the scene. However, I cannot pin the toolbar to the superview. As a result he toolbar rests at the bottom of the tableview so it is not anchored. See attached screenshot. I suspect I am overlooking something simple. Any suggestions are appreciated.
Thanks!
Attached Files
#5
Posted 07 February 2015 - 03:45 PM
thats coz you added it to the tableView acting as a footer.. so you cant pin it to the superview..
you need to add it to the view instead
P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.
#6
Posted 08 February 2015 - 08:04 AM
Thanks for the suggestion ozie. It's an STV created detail view and it doesn't contain a superview -- just a tableview. I added a view in IB and placed the toolbar inside it; but because there's no superview, there's no way to anchor the view to the bottom -- so the view and toolbar remain anchored to the bottom of the tableview just like the image in post #4.
If I set Simulated metrics/Bottom Bar to Translucent Toolbar I am able to add Bar Button Items to the toolbar anchored at the bottom of the view. However, these Bar Button items appear in the Detail View IB, but not on the simulator or the device. See screenshot.
This is odd because I have a near identical arrangement in the Master View and the toolbar and buttons appear in IB and on the simulator and device at run time. I'm at a loss for why it works in the master view but not the STV-generated detail view.
I even tried using a custom detail view controller and variations of the following code to try and show the toolbar:
class DetailViewController: SCTableViewController { override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) //self.navigationController?.toolbar.hidden = false self.navigationController?.toolbarHidden = false } override func viewDidLoad() { super.viewDidLoad() //self.navigationController?.toolbar.hidden = false self.navigationController?.toolbarHidden = false } }
... but nothing works.
Attached Files
Edited by Donovan Dillon, 08 February 2015 - 12:53 PM.
#7
Posted 08 February 2015 - 01:54 PM
yeah doing it that way in IB isnt right...
for IB the only way that works is to go to the parent Navigation Controller and tick Show Toolbar.. but then all child views have a toolbar
i dont do swift but in code this should work [self.navigationController setToolbarHidden:NO animated:NO];
P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.
#8
Posted 08 February 2015 - 10:25 PM
Hi ozie, I actually tried it in code as you suggested. I used the following code:
class DetailViewController: SCTableViewController { override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) //self.navigationController?.toolbar.hidden = false self.navigationController?.toolbarHidden = false } override func viewDidLoad() { super.viewDidLoad() //self.navigationController?.toolbar.hidden = false self.navigationController?.toolbarHidden = false } }
The toolbar still did not appear. The Bar Button Items are added in IB. Do I need to ad them via code as well?
#9
Posted 08 February 2015 - 11:27 PM
its not showing because your not adding any buttons to it
try this
self.hidesBottomBarWhenPushed = false var items = NSMutableArray() var systemButton1 = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Play, target: nil, action: nil) items.addObject(systemButton1) self.navigationController?.toolbarHidden = false self.setToolbarItems(items, animated: true)
run and let me know if it shows with a play button
Edited by ozie, 08 February 2015 - 11:37 PM.
P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.
#10
Posted 15 February 2015 - 10:12 AM
its not showing because your not adding any buttons to it
...
run and let me know if it shows with a play button
Hi ozie,
Thank you. I tried your test snippet and it sort of worked:
1. No Play button is visible in the detail view toolbar if I start from the Master view, and select an object to display in the detail view
2. If I then drill-down from the detail view to create or edit a child entity then return to the detail view the play button will appear in the toolbar
3. If I then return to the Master view and select an object to display in the detail view the Play button will appear in the Detail view
4. If I stop the simulator and restart it, sequence 1-3 recurs
You can view a video here: https://cloudup.com/c7arV_EBQsN
Here is the code in the Detail view controller:
class DetailViewController: SCTableViewController { override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) self.hidesBottomBarWhenPushed = false var items = NSMutableArray() var systemButton1 = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Play, target: nil, action: nil) items.addObject(systemButton1) self.navigationController?.toolbarHidden = false self.setToolbarItems(items, animated: true) } override func viewDidLoad() { super.viewDidLoad() } }
Any explanation/fix for this behavior?
Also, I am probably missing something very basic but I still think it is odd that toolbar buttons added in IB won't show up in STV-generated detail views. This means you have to subclass every STV-generated view and use code to add toolbar buttons -- something that appears to be supported in IB on those STV-generated views.
Thanks again for all your help ozie.
Edited by Donovan Dillon, 15 February 2015 - 10:29 AM.
#11
Posted 15 February 2015 - 07:32 PM
not everything in life can be done in IB still at times even have to put logic into what happens when the button is tapped:)
put the code in viewDidLoad not willAppear and see if that fixes it
and time to clean your mail inbox too:P 8000+ is too many hehe
P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.
#12
Posted 15 February 2015 - 09:04 PM
Hi ozie,
I put the code in viewDidLoad and the change had no effect -- the app exhibited the same behavior -- l had to drill down into child scenes before the toolbar would appear in the detail view.
Very strange.
#13
Posted 16 February 2015 - 02:23 AM
if you put a breakpoint on the code.. does it stop the first time the form loads?? so we can test that it is trying to set the toolbar items when the view shows
P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.
#14
Posted 16 February 2015 - 05:38 AM
@Donovan, maybe I'm not understanding fully. I have a project at present, that has some custom buttons in an auto-generated detail view. I did create all this in IB.
Basically, I have an SCObjectSection. In IB I added an object. It's linked to something, but that doesn't matter. Add a cell - change the number of rows in the objectSection > number of rows. The last cell will duplicate the previous entry. Clear that. Change the cell to a custom cell (SCCustomCell), add UIButtons, and you should then be able to attach actions to those buttons.
Here are a few configuration screen shots.
Screen Shot 2015-02-16 at 8.29.53 AM.png 21.28K
3 downloads
Screen Shot 2015-02-16 at 8.29.45 AM.png 26.73K
3 downloads
If this is in the right track for you, let me know and I can show more images...
#15
Posted 16 February 2015 - 06:31 PM
@David - Donovan is trying to get some toolbar buttons to show in the detail view using the built in navigationbar toolbar.. (not trying to create a button as a cell)
P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.
#16
Posted 17 February 2015 - 08:19 AM
Sorry, it's sometimes tough not being able to see very well.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users