What is the difference adding view directly without following code - coronasdk

function main()
display.setStatusBar( display.HiddenStatusBar )
mainGroup:insert(director.directorView)
director:changeScene("titlescreen")
end
I'v not used this code instead directly called
director:changeScene ( "splash" )
its running but then why we do the above coding.

display.setStatusBar(display.HiddenStatusBar) is used to change the appearance of the status bar. You can see more here.
mainGroup:insert(director.directorView) is of adding the group from director class. And this implies that director view is used as master page. See more...
director:changeScene("sceneName") is used to the transition between scenes.
As you said, the code will work without the 1st and 2nd lines, but when you come back to the page from next page, it may cause director error.
Keep coding... :)

Related

Unable to add SSSnackbar to view tied to viewcontroller

I'm using SSSnackbar for iOS: https://github.com/stonesam92/SSSnackbar and I am following their example exactly. Problem is, it works on some view controllers that I have and do not work on others.
Specifically, in one viewcontroller which has its view defined completely by its corresponding XIB file, when I try to show the Snackbar, it says:
Unable to interpret '|' character, because the related view doesn't have a superview
Which refers to this line in the source code:
[NSLayoutConstraint constraintsWithVisualFormat:#"H:|-6-[self]-(6)-|"
In this particular viewcontroller I don't call self.view or addSubview at all, since it is completely defined by an XIB file tied to it. My question is, how do I get the snackbar to work correctly with that?
Wow I'm an idiot, its because I need to call it in ViewDidAppear.....hope this helps someone else out.

PROPER way of creating Custom Segue

Now, yes, there are hundreds of questions (and answers) of how to perform custom segues. However, and I'm no exaggerating, ALL of these answers are wrong (all 50+ I've seen)! Sorry, this might sound harsh, but the truth is, NONE of the suggested answers gives the same (correct) result as Apples built in transitions do (vertical cover etc.).
To be more specific, this is the result that's expected (confirmed with logs):
Segue begins (adds view to hierarchy, invokes viewWillAppear on destinationVC and viewWillDisappear on sourceVC and starts animation).
animation is performed for the whole duration
Segue ends (animation finished, sets the destinationVC as the current VC, either on stack or modally presented. Invokes viewDidAppear on destinationVC and viewDidDisappear on sourceVC).
In short: invoke viewWillAppear/Disappear -> animate transition -> invoke viewDidAppear/Disappear
Using apples built-in segues, this is the expected behavior but somehow not a single soul except me have had issues with this. A lot of versions even add the destination-view as subview first, animates it then removes it again and calls
[srcVC presentModalViewController:destVC animated:NO];
or
[srcVC.navigationController pushViewController:destVC animated:NO];
causing the view-events to be sent in all kinds of random order (same issue with CoreAnimations).
In my case, all I really want is the "Vertical Cover"-transition reverted (top to bottom), with all other events sent EXACTLY as expected (shown above).
So, am I just supposed to live with all kinds of ugly workarounds (doing my "tasks" in hard-coded methods called whenever I need them to etc.), or is there some hidden proper way of doing this in a reusable manner?
Funny thing: Even apple suggest that you do it the "wrong" way, making it seem like the right way but with inconsistent outcome compared to their own ways… So my best guess is that apple do this under the hood, and forgot to give enough flexibility for clients to perform the same operations (big flaw in other words), or that I'm just on some bad trip and see some issue that doesn't exist…
Okay, this might not be a true answer of how to solve it for custom segues (subclassing UIStoryboardSegue), but it does solve the general issue!
After some casual reading about new features, I stumbled upon a new way to do custom transitions between ViewControllers introduced in iOS7 called nothing more than "Custom Transitions" i guess!
Read about it here and here, or video from WWDC here.
I've just dipped my toes, but basically it is a new, closer to the system way of doing transitions and allows for better control = better looking transitions. After glancing at the example provided by the blog I referenced (git found here) I can confirm that FINALLY, we are able to do transitions which behave as ONE EXPECTS THEM TO with events fired at the expected occasions!
Since I'm just reading about it I can't give a thorough explanation yet, but check out the links :)
Note: This is maybe not supposed to completely replace custom segues, but can be used in a similar fashion (check examples) so if you need that little extra fancy transition, this is definitely the way to go by the looks of it! Basically you setup segues in the storyboard, and hook up the correct transition-delegates in the prepareForSegue:-method.

UITabViewControllers - Load Second View first based on some conditions

Beginner here.
I'm trying to make an iOS app using the Tab View Controllers, and I kinda ran into a problem , at least I don't know how to do it .
The Tabs Look like this : First Choice, Second Choice, Settings ( here I'll have some text fields and a save button , and everything will be saved in a plist. ) .
Basically what I'm trying to do is , the first time the App is lunched, i want to make an if statement to check if the plist file exists and the data is there. IF Yes , just load normally with the First Choice View Controller , if NOT , Load Settings View Controller .
Any ideas on how to do this?
Thank you
This is a relatively contrived example because no sample code was provided but it should work.
In your applicationDidFinishLaunchingWithOptions or you could do willEnterForeground, run your plist check.
Then depending on the success or failure set the selectedIndex which is a property of UITabBarController to whichever one you'd like.

Corona SDK Storyboard: how to access the associated display group from my custom callback

I only know basics in using storyboard. I created a scene without problem, and then I added my own callback (returned from a asynchronous http request). Therefore in my scene Lua file, I have following
local function httpCallback(data)
// process data
// screen update
end
For "screen update", I don't have access to the associated display group, which I mean the "self.view" in the scene listeners, for example,
function scene:createScene( event )
local group = self.view
end
How do I get access to the "self.view"? I was thinking to use a variable to track self.view, but with "asynchronous" callback, I am afraid self.view would have become nil before I find out?
What's the proper way for this?
Thanks.
At the top of your storyboard module you should have the line:
local scene = storyboard.newScene()
or something similar. This is your scene. for the event handlers like createScene() and such they get passed "scene' as "self". Therefore you can always (after createScene() is first called) refer to the scene's view (a display.newGroup for all intents and purposes) using the code:
scene.view:insert(someDisplayObject)
which means you can also do:
local group = scene.view
and then use the group reference if you prefer.

Working with self.view after refactoring code

I've been doing some testing with a cool charts framework (http://www.shinobicontrols.com/shinobicharts/) and so far I got them working on my project. They look great!
Just as I do on any tests, I implement the examples as simple as I can and then, when it's working, I move on to improve things a bit in the code-organization department.
After I felt comfortable with what I had I started refactoring the code a bit. Now I can't get the charts to draw on my view. I've tested the calls to methods with NSLog and everything is being called as expected. It is the view handling what got me spinning here. Let me explain what I had (when it was working) and what I did (to broke it).
Working scenario:
ReportsViewController
1) Imported chartLibrary.h
2) Imported chartDatasource.h
3) Created view and added with [self.view addSubview:chart];
All in the same place. All good.
What I did to organize my code:
1) Created a new class "ChartReports" (first I thought it should be NSObject but then I couldn't work with views so I changed to UIViewController)
2) Moved all imports and drawing code to this new class. Create drawing methods for each type of chart.
3) Imported "ChartReports" into "ReportsViewController"
4) Created new object (of ChartReports type) and called the new method to "drawChartX" in the exact same place as I had the whole code before (inside "ReportsViewController")
It all went south :(
The thing is that the call is correct, the method "drawChartX" is called and I NSLog from beginning to end to make sure the code is executing, but nothing is draw in the screen.
I create it and call it like this:
ChartReports *chart = [[ChartReports alloc] init];
[chart drawChartX];
When I see the code I moved (from "ReportsViewController" to "ChartReports") I notice it still says "self.view" everywhere. I thinks this is the place where the drawing is breaking. "self" originally referred to "ReportsViewController" and now it means "ChartReports".
So, after all of that: How can I tell "ChartReports" to draw on "ReportsViewController".view and not on its own view?
I tried variables and properties with no luck. Should I maybe send the name of the view as a method parameter?
I'm sorry to post such a long explanation but I'm out of ideas to try. Any general tip would be more than helpful to get back on the right path.
Thanks as usual,
Your ChartReports object should not draw on your ReportsViewController, this would break basic MVC principles. Instead, you should organize your code so that the ChartReports object creates and returns a view (i.e. the chart) that your ReportsViewController will then add to its view using addSubview.
In this way you can still encapsulate the creation of the charts in a separate object (ChartReports) but you are leaving the work of displaying the chart to your view controller, which is its job.

Resources