I am currently working on an iPhone 2.1 application. I am new to Objective C, coming from a Java background.
My application has as a base the Utility Application template available in Xcode with the iPhone SDK. Currently I have some controls, such as an UISlider and text box, in the FlipsideView. The UISlider already has a method which is being called when the value changes, using targets and selectors. However, I would also like to be able to read, from the MainView, the current (or last) value of the UISlider and textbox.
Keep in mind I am new to development on a Mac, and would appreciate any guidance as to where I should look up such information, be it through the use of delegates or perhaps I am missing something obvious in the structure of the template.
UPDATE:
I am taking a look at the structure and have some more details: The UISlider is being created in FlipsideView.m. I noticed that the Done button is created from RootViewController.m and probably I should move the UISlider code over there. I may incorrectly be using the View to keep code that would be more appropiate in a Controller.
Ultimately you should be updating some underlying object with the values from the controller. In general, the slider belongs in the view layer - it's a display element. The action that adjusting the slider produces, however, is a component of the controller and it should fire back into your model to update a value. I highly recommend drawing boxes on a sheet of paper and trying to produce a clean a separation as possible for your application's layers - doing so in this case would produce two views for each "side" of the utility which would, via a controller, relate to a model. Then, the act of moving the slider would "instantly" update the model on the back. The Cocoa Fundamental video on the iPhone developer site demonstrates this to great effect.
I'm in exactly the same situation: first iphone app, new to mac programming, creating a utility, sliders on the flipside.
By following the example and the free tutorial here (http://www.bestechvideos.com/2008/11/13/writing-iphone-app-free-episode) I determined that the sliders and other controls should be declared on the flipsideviewcontroller. (Which leave the view pretty empty - I guess the use of the Nib resource file for the UI leaves the ...View.m class pretty much redundant?)
Wisequark's answer is a bit to general to help me though.
In terms of specifics:
- I can't find that video is there a link?
- Could we see some code showing the Controller-Model code?
- How do I persist the values set on the slider without having to build UI to go in the system settings?
(BTW is an Answer the right place to add to the question?)
Related
I am trying to get a wiki page to display on IOS. This is the first assignment in my 8-week course and I am completely lost. I have only worked with Java, Swift is a completely new language and I cant seem to find a starting point. My professor has only showed us how to bring objects into the view controller such as segmented control bars and buttons, but has not showed us how to implement code into program to interact with the objects.
I know this is a long shot, and I have exhausted all other options (even bought an IOS 9 book) but if anyone can provide a starting amount of code for me to see and work with I would be extremely grateful. I am not asking for the whole project, I just need to be able to see an example of some starting code that I can hopefully follow and progress with.
Project Details /
Project Example Images
From reading the instructions, it seems like you'll need to have a multi-component UIPickerView (this is a basic tutorial, you can use it to get the delegate methods used to interact with the pickerView, here's a more in depth tutorial) and definitely will need to use multiple UIViewControllers in order to achieve the desired result. Add BarButton Items to the bottom of the view, and control+drag on those to connect them to additional ViewControllers which can be used to select Plant/Animal Name, and to change the textColor.
On the initial viewContoller, you'll need a WKWebView above your imageView, learn more about their implementation here (note that this shows a programmatic approach, your wkWebView will likely be connected to your code from Interface Builder using an IBOutlet).
Continue to ask questions as they arise.
So a few weeks ago I got into Swift and before that I learned a bit Web dev. When learning web development there was always a certain structure to follow for any project. Like specifying where to get the stylesheet from, where to get the JS and that information was put into the head of an html. It is not easy to put my question into words, but is there a general structure for iOS projects? So far I realized that there is always an "import" for example at the beginning of any file to add a framework and then a class. But there is always just one class and all the code goes into that class, why? What else stays always the same for iOS projects?
There are a couple of ways you can approach developing an iOS project. But generally this is what you need to know.
All your UI related designs can be implemented in Main.storyboard file in your project. Here you can create a View Controller and add various UI elements to them like button, labels etc.
To make sure your views look the same across all device screen sizes, you need to use autolayouts which is the process of setting constraints to the UI elements so that they can be resized according to the screen size of the device they are being displayed on.
For each View Controller created you have to assign a class file which is a .swift file. In this class file you have a function by default called viewDidLoad(). This method is executed when the view is displayed on the screen after running the code.
For each UI element in a View Controller you can add IBOutlets and IBAction to their respective class file.
Here are a few links that can help you more:
Tutorial for autolayouts: https://www.raywenderlich.com/443-auto-layout-tutorial-in-ios-11-getting-started
Tutorial for Swift programming: https://www.raywenderlich.com/6338-swift-tutorial-part-1-expressions-variables-and-constants
Get started with iOS: https://codewithchris.com/how-to-make-an-iphone-app/
Some other useful links:
https://medium.com/ios-os-x-development/7-things-you-must-absolutely-do-before-writing-an-ios-app-a8bacf710c57
https://www.raywenderlich.com/477-design-patterns-on-ios-using-swift-part-1-2
I'm a complete newbie with Objective-C, Xcode, and the design itself. I have had a bit more experience developing iOS on Xcode, and when you wanted to link an action (i.e Slider changing value), you could select from many options unlike OS X.
How can I get around this with the same results, as using a pre-generated (control-drag slider to ViewController.h and .m) only fires an action at the mouseUp action.
EDIT #1: Sorry for making my question quite confusing. I am wondering how to receive actions while dragging.
Here's whats happening in picture form:
Most likely something very easy that I'm not getting at all.
I think you did not set controller from Storyboard. Please verify your controller class is properly set by following the image below
Your question is very confused. Are you trying to ask how to make a slider send its message while dragging, instead of just at the end?
On Mac, controls only have one target/action, there are no multiple actions. Objects have other properties that control when the actions are actually sent, if needed. In case of NSSlider, you probably forgot to set its 'continuous' property.
In CareKit there are Care Card and Symptom tracker. I'm not understanding how to customize Carecardviewcontroller and symptomtrackerviewcontroller. I don't want to use these view controllers but interested in using components of these view controllers. there is no clear documentation to explore this.
(source: carekit.org)
If you are coming at this from a Swift perspective, then it has to be admitted that CareKit is about as "un-Swifty" as anything you can imagine. The GitHub site is certainly a start, but there is a horrific gap between reading the programming guides there and actually implementing a solution. It certainly has been a long slog for me!
That said, you can add customization to CareKit's story-board-free approach by using the view controller delegate functions that CareKit provides.
For example, suppose you have an app that reminds your user to perform two intervention activities, (1) take aspirin and (2) go for a brisk walk. If the user opens the Care Card and taps an event icon (one of the circles) for "take aspirin" then that will fire a method in the OCKCareCardViewControllerDelegate called:
careCardViewController(_ viewController: OCKCareCardViewController,
didSelectButtonWithInterventionEvent: OCKCarePlanEvent)
In this method you can segue to whatever view controller you'd like. E.g. if the event is for taking aspirin then display a view controller that shows a photo of an aspirin table, a reminder that it should contain just an 81 mg dose, and a recommendation about taking it with water.
Of course, nothing is ever easy with CareKit. It turns out that you will probably also want to turn off CareKit's standard practice of calling an event completed if the circle icon is tapped. That is accomplished by returning "false" from another delegate method called:
careCardViewController( _ viewController: OCKCareCardViewController,
shouldHandleEventCompletionFor
interventionActivity: OCKCarePlanActivity )
-> Bool
There is a book called Beginning CareKit Development that I can cautiously recommend. It was written for an earlier version of Swift and you have to do a lot of "translation" to get things to work with Swift 3. The last time I checked the GitHub repository for the code associated with the book was also entirely in this earlier version. APress will provide the code updated to Swift 3 if you ask. On the Kindle there are numerous little glitches with the book, including an index that has no page numbers nor hyperlinks to the associated text, very odd formatting choices that make the text sometimes hard to distinguish from code, and occasional errors in the solution code. All that said, I doubt that I'd have made any progress with CareKit without the book's help.
I've been looking for this answer myself.
As far as I researched, you can customize this screen visually with UIAppearance.
AND/OR you can create a new screen like this one from scratch using its behavior.
You can check the CareKit source code for hints on this: https://github.com/carekit-apple/CareKit/tree/master/CareKit/CareCard
There you'll notice some interesting classes/files:
OCKCareCardWeekView
OCKWeekLabelsView
OCKHeartView
OCKHeartButton
OCKWeekViewController
OCKHelpers
CareKit draws each screen via code. You can see how they do it by reading the code.
The idea is to create your own ViewController with these pieces, or one from scratch.
Surely it's not as trivial as just using CareCardViewController, but this will get you there.
I was wondering what would be the best configuration of view controllers and views for an app that I’ve been planning out. Conceptually, the way I would like to lay out the app is with an initial loader/browser view, likely with document thumbnails. When a user chooses to open one, a new view comes up that forms the main document-editing mode. The user can also choose to bring up a third view that contains an alternative document-editing mode.
I suppose this is very much like the way the Pages for iPad works, with first a row of document thumbnails to choose from, then the main word processing view, and accessible from a popover a third page setup view. Document browser view, and two document editing views.
Now, I can think of, and have been playing around with a few different set-ups, but in each case I can see problems that I’ll be running into later. So really, I’m looking for advice on a configuration that you think would keep things as neat and manageable as possible.
I hope this is not too open a question, and I would very much appreciate any answer.
Thank you,
I will probibly get shot in the head for making a suggeston like this, but I'll make it anyway:
In learning iOS programming, I spent a lot of time studying (as most people do - and as is taught by every tutorial on the planet) on how to use Navigation Views, and toolbars, and all the standard type views that assist in different types of navigation.
On the latest app I have been working on - I spent a lot of time and frustration trying to figure out how to best characterize what I was doing - and moreso trying to fit it into what the iOS frameworks would use to implement this stuff. Then (of course) I got stuck trying get things to do what they weren't supposed to - like when a navigation view wouldn't let me use the "back" button to jump out of the navigation herirarchy I'd set-up, etc.
In short - when I stopped worrying about the specifics of what all these different types of views and controllers were - and how they interacted and how I was supposed to do it - and started worrying about how I wanted my application to work - and working from a basis of generic views, custom toolbars, etc - the whole think made a whole lot more sense.
In my case, I liked the look-and-feel of the Mapquest app - and they way it dealt with toolbars that your could open and close from the top and bottom of the screen - which had buttons - which could switch to other views etc. So I started using "generic" views to implement this functionality - and the whole entire thing clicked together.
So in-short:
1 . I'd decide how you want it to look and what you want it to do
Use a third-party app as your inspiration, if needed
Decide when/where/if some of the "standard" practices apply - and use them where/when they do.
Have fun!
-BKG