来自先前VC(来自API)的数据无法传递到另一个VC

时间:2018-08-28 08:05:37

标签: ios swift alamofire

该场景应该是,我将输入有效事件代码以便在应用中登录,如果我输入了有效事件代码,则应该分派 DashBoard 并事件详细信息应显示在上面。 DashBoard 已成功调度,但标签中未显示任何事件详细信息,控制台中还显示了无法插入COPY_SEND 。实际上, event validpincode 应该为nil。 event and validpincode turns nil。我对问题出在哪里感到困惑。 _无法插入COPY_SEND_或无法从API获取数据。我看到了很多有关COPY_SEND问题的问题和解决方案,但是我发现这对我的问题有所帮助。希望您能给我一些时间来帮助我。谢谢

showEventDetails函数

$args= array('post_type' => 'sfwd-courses',
            'post_status' => 'publish',
            'order' => 'DESC',
            'orderby' => 'ID',
            'mycourses' => false);
$loop = new WP_Query( $args );
 while ( $loop->have_posts() ) : $loop->the_post();
    endwhile;

从View Controller中验证事件密码

var validPincode: String!
var event: Event!


@IBOutlet weak var eventNameLabel: UILabel!
@IBOutlet weak var dateTimeLabel: UILabel!
@IBOutlet weak var locationLabel: UILabel!




override func viewDidLoad() {
    super.viewDidLoad()

   configureAALoading()

    guard event != nil,
        validPincode != nil else {
            _ = SCLAlertView(appearance: appearance).showError("No Event Details", subTitle: "There's no event details, please logout and try again")
            return
    }

    showEventDetails()
}
func showEventDetails() {

        DispatchQueue.main.async{
            self.eventNameLabel.text =  "\(self.event.name.uppercased())"
            self.locationLabel.text =  "\(self.event.location.uppercased())"

            if let dateStringFromDate = getFormattedStringFromDate(date: (self.event.startDateTime), formatString: "MMMM dd, yyyy/ hh:mm a") {
            self.dateTimeLabel.text = dateStringFromDate
        } else {
            self.dateTimeLabel.text = "-"
        }
    } 
}

将ViewController中的Dashboard搜索到DashBoardController

 func validateEventPasscode(){
    //Show Loading
    self.view.squareLoading.start(0.0)


    let api = APIService(APIKey: passcode)

    api.validatePasscode(passcode: passcode, successBlock: { (event) in
        // VALID PASSCODE AND NOT DELETED OR CLOSED EVENT

        self.event = event
        self.view.squareLoading.stop(0.0)

        self.performSegue(withIdentifier: "showEventDashboard", sender: self)
        self.enteredEventCode.text = ""

APIService

   override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "DashBoardViewController" {
        if let DashboardViewController = segue.destination as? DashBoardViewController {
            DashboardViewController.event = self.event
            DashboardViewController.validPincode = self.passcode
        }
    }
}

0 个答案:

没有答案