carekit-apple / CareKit

CareKit is an open source software framework for creating apps that help people better understand and manage their health.
https://www.researchandcare.org
Other
2.41k stars 443 forks source link

Adding a detailed description to the nausea card #702

Closed th1970 closed 1 year ago

th1970 commented 1 year ago

Hello. In my carekit application, the nausea card task(which actually shows the fecal incontinence(便失禁))is displayed as follows.

var query4 = OCKEventQuery(for: date)
                    query4.taskIDs = ["nausea4"]

                    if let nauseaTask = tasks.first(where: { $0.id == "nausea4" }) {

                        print("Nausea task found")
                        let viewSynchronizer = OCKButtonLogTaskViewSynchronizer()

                        let nauseaCard = OCKButtonLogTaskViewController(
                            query: query4,
                            store:self.store, // pass the underlying store here
                            viewSynchronizer: viewSynchronizer
                            )

                        listViewController.appendViewController(nauseaCard, animated: false)

I want to add an image and a description on the screen that appears when I click the” → “part, but I didn't know the class that does this. Anyone have any good ideas? Thanks in advance.

Simulator Screen Shot - new - 2023-08-28 at 11 04 36

Pasted Graphicのコピー2

gavirawson-apple commented 1 year ago

The easiest way to do that is to specify the image and instructions on the task itself before it's added to the care store:

var task = OCKTask(...)
task.instructions = "Write your instructions here"
task.asset = "name-of-image-in-assets-catalog"
store.addTask(task)

If you happen to need even more control than that, you can override the method that's called when the detail disclosure is tapped. That method is called OCKTaskViewController.didSelectTaskView(taskView:eventIndexPath:). In that method you can instantiate and display a custom view controller that contains details for your task.

th1970 commented 1 year ago

Sorry for the late reply. Thank you for answering. I was able to implement it following your advice. Thank you very much.

class AppDelegate: UIResponder, UIApplicationDelegate {
let careKitStore = populateSampleData2()

...

func populateSampleData2() -> OCKStore{
 let store = OCKStore(name: "SampleAppStore4", type: .onDisk())

...

var nauseaSchedule = OCKSchedule(composing: [
            OCKScheduleElement(start: beforeBreakfast, end: nil, interval: DateComponents(day: 1),
                               text: "随時", targetValues: [], duration: .allDay)
        ])
var nausea_1 = OCKTask(id: "nausea4", title: "便失禁あればクリック",
                                 carePlanUUID: nil, schedule: nauseaSchedule)

    nausea_1.instructions="便失禁は、便が漏れる状態で各年代7%程度存在すると言われています。\n骨盤体操は症状を改善する有効な手段です。"
    nausea_1.asset = "IMAGE2"
store.addTasks(nausea_1, callbackQueue: .main){ result in
                    switch result{
                    case .failure(let error):
                        print("Error adding tasks_1: ")

                    case .success:
                        print("Successfully added tasks")
                    }
                }
...
}
return store
}

Simulator Screen Shot - new - 2023-09-09 at 17 33 10 Simulator Screen Shot - new - 2023-09-09 at 17 33 53

gavirawson-apple commented 1 year ago

Incredible! I'll go ahead and close this issue out.