2015-11-27 28 views
0

我在Swift上爲iPhone iOS 9.1使用Xcode 7.1.1與ResearchKit編碼。我正在嘗試創建同意頁面,並一直在網上尋找試圖找到沒有成功的例子。如何在ResearchKit上創建個體同意頁面?

http://www.raywenderlich.com/104575/researchkit-tutorial-with-swift,我已經得到了代碼:

import Foundation 
import ResearchKit 

public var ConsentDocument:ORKConsentDocument { 

let consentDocument=ORKConsentDocument() 
consentDocument.title = "Consent" 

//Consent Sections 
let consentSectionTypes: [ORKConsentSectionType] = [ 
    .Overview, 
    .DataGathering, 
    .Privacy, 
    .DataUse, 
    .TimeCommitment, 
    .StudySurvey, 
    .StudyTasks, 
    .Withdrawing 
] 
let consentSections: [ORKConsentSection] = consentSectionTypes.map { contentSectionType in 
    let consentSection = ORKConsentSection(type: contentSectionType) 

    consentSection.summary = "If you wish to complete this study..." 
    consentSection.content = "In this study you will only be asked 10 easy question!!!" 
    return consentSection 
} 


consentDocument.sections = consentSections 

// Getting Signature 
consentDocument.addSignature(ORKConsentSignature(forPersonWithTitle: nil, dateFormatString: nil, identifier: "ConsentDocumentParticipantSignature")) 

return consentDocument 
} 

的問題是,這個代碼創建一個相同的摘要和內容的每一頁。我如何爲每個單獨的部分創建單獨的頁面?

+0

您可以使用一個開關塊地圖內,針對不同的'contentSectionType'分配不同的字符串。 – Yuan

+0

@袁你能舉個例子嗎?我正在嘗試 ''開關consentSectionTypes案例consentSectionTypes.Overview: Overview.summary =「如果你想完成這項研究...」 Overview.content =「在這項研究中,你只會被問到10個簡單的問題! !!「 '' – Tendouji

回答

0

袁建議按照以下步驟更換您的地圖功能:

let consentSections: [ORKConsentSection] = consentSectionTypes.map { contentSectionType in 
    let consentSection = ORKConsentSection(type: contentSectionType) 
    switch contentSectionType { 
    case .Overview: 
     consentSection.summary = "Overview" 
     consentSection.content = "Overview - Content" 
    case .DataGathering: 
     consentSection.summary = "DataGathering" 
     consentSection.content = "DataGathering - Content" 
    case .Privacy: 
     consentSection.summary = "Privacy" 
     consentSection.content = "Privacy - Content" 
    case .DataUse: 
     consentSection.summary = "DataUse" 
     consentSection.content = "DataUse - Content" 
    case .TimeCommitment: 
     consentSection.summary = "TimeCommitment" 
     consentSection.content = "TimeCommitment - Content" 
    case .StudySurvey: 
     consentSection.summary = "StudySurvey" 
     consentSection.content = "StudySurvey - Content" 
    case .StudyTasks: 
     consentSection.summary = "StudyTasks" 
     consentSection.content = "StudyTasks - Content" 
    case .Withdrawing: 
     consentSection.summary = "Withdrawing" 
     consentSection.content = "Withdrawing - Content" 
    default: 
     break 
    } 
    return consentSection 
} 
相關問題