ResearchKit ORKLineGraphChartView Get data at touchpoint - ios

I am trying to figure out how to detect the datapoint touched within a ORKLineGraphChartView so that I can take action on the datapoint selected, for example, more data for a date datapoint. I implemented the protocol ORKGraphChartViewDelegate, but can not find any functions on the delegate that return a touchpoint/datapoint for the chart. I can add a tap gesture to the chart view to get the X/Y of the touchpoint, but then I'm not quite sure how to get the datapoint for that location within the chart. Any help is appreciated.

For this, what I ended up doing was digging through the Objective-C classes and found a function that did exactly what I needed, but it hadn't been implemented in swift yet. So I created a bridging header in my application:
Bridging Header import:
#import "ORKLineGraphChartView+ORKLineGraphChartView_PointIndex.h"
And then I created another file which I used to expose the Objective-C function on the class ORKLineGraphChartView:
#import <ResearchKit/ResearchKit.h>
#interface ORKLineGraphChartView (ORKLineGraphChartView_PointIndex)
- (NSInteger)pointIndexForXPosition:(CGFloat)xPosition plotIndex:(NSInteger)plotIndex;
#end
This worked perfectly until hopefully swift contains all the functions from research kit. Hope this helps someone.

Related

Send image from Objective VC to Swift configured VC

I am working on a project which somewhere needs to send the edited image to another ViewControler using segue or storyboard.
Some points to understand first.
The ViewController i am sending image which is configured using Objective C.
And the image is to be pass that ViewController which is configured using Swift Lang.
Problem:
The Swift Class which is imported in Objective .m file is not visible so it lets me to create its object to make reference of its members.
I tried:
// here i am not able to create SwiftVC class object so i can pass image further
SwfitVC *object = [self.storyboard instantiateViewControllerWithIdentifier:#"VC_Identifire"];
object.image = image;
[self.navigationController pushViewController:object animated:YES];
SwftVC Class is not visible after importing to .m file.
Please have look. Thanks.
In order to make your Swift file visible; in your .m file you'll have to write this import statement.
#import "YourProjectName-Swift.h"
Clean and build then you'll be able to use your Swift class.
Alternate way:
You can save the image to Document Directory in Objective-c class and fetch it into Swift Class.
Might be a help this logic.

Expandable and collapse tableview in swift

I don't know how to implement expandable and collapse tableview in SWIFT. I searched, but nothing in swift. Kindly guide me. How to do that?
My required output
This looks like a framework like CollapseClick.
It's a framework written in Objective-C.
But you can easily implement it in your Swift-Project. Just copy the .h and .m into your project and link it in your Bridging-Header.h file:
#import "CollapseClick.h"
#import "CollapseClickCell.h"
#import "CollapseClickArrow.h"

xcode 4 drawing rectangles

i'm very new to xcode. i've googled this and even serched here and i didn't find exactly what i was looking for. i really wanna get this. especially since it's the most basic thing there is.
so, i have the .h and .m files
i want to DRAG a uiview into the .xib file, i don't want it to be as big as the screen, so i resize it.
now i want to draw a bunch of rectangles INSIDE this view object.
how do i go about doing this?
your help would be greatly appreciated!
So you add a generic UIView then create a subclass of UIView and do your drawing inside the drawRect method.
Then change the class of the UIView to your subclass name in the inspector.
Be sure to #include your header in the app delegate.
That's the basic thing.
For more sophistication, you're going to want to learn to use UIViewController subclasses as well. These are used all over ios.

Object Properties From Custom Classes in iOS

This should be easy - but I am scratching my head over it. Here's the problem:
I have a custom class that I import into my MainViewController.h file. The class contains a bunch of properties and a few methods.
I instantiate an object of this class in the ViewDidLoad section, and can run any of the methods or alter the properties on this object at will... they work fine as long as I stay within the ViewDidLoad section.
I created a button with which I wish to activate one of my custom class methods on this object, but the IBAction section seems out of scope, as it doesn't see the object created in ViewDidLoad at all.
Can someone point me in the right direction to enable these two areas to see eachother?
Thanks in advance!

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