iOS Pull To Refresh ไม่ทำงานบนอุปกรณ์เฉพาะเช่น iPhone X

ฉันกำลังใช้การดึงเพื่อรีเฟรชสำหรับการรีเฟรชข้อมูลตามปกติในมุมมองตาราง

นี่คือรหัสของฉัน

-(void)addUIRefreshControl{

    //Instantiate and Configure Refresh Control

    self.refreshControl = [[UIRefreshControl alloc] init]; // initialize refresh control
    self.refreshControl.tintColor = [UIColor appBaseColor]; // set tint color
    [self.refreshControl addTarget:self
                            action:@selector(refreshAPI)
                  forControlEvents:UIControlEventValueChanged]; // add target

    [self.tableView addSubview:self.refreshControl]; // add the refresh control

}

-(void)refreshAPI{

    if ([APP_DELEGATE isNetAvailable]) {
        [self fetchAPI];
    }else{
        if (self.refreshControl) {
            [self.refreshControl endRefreshing]; //end refreshing
        }
    }
}

ทุกอย่างทำงานได้ดีบนอุปกรณ์ iOS & Simulator ยกเว้น iPhone X มีใครแนะนำได้ไหมว่าฉันทำอะไรผิด

ขอบคุณ


person Amit Majumdar    schedule 17.05.2018    source แหล่งที่มา
comment
ย้าย RefreshControl ไปที่ superview ใน viewDidAppear   -  person Nilomi Shah    schedule 07.08.2019


คำตอบ (1)


แอพของคุณเป็น iOS 10 และใหม่กว่าเท่านั้นใช่ไหม หากเป็นเช่นนั้น คุณควรใช้บรรทัดแสดงความคิดเห็นของคุณ:

- (void)addUIRefreshControl{
    UIRefreshControl * refreshControl = [[UIRefreshControl alloc] init]; // initialize refresh control
    refreshControl.tintColor = [UIColor appBaseColor]; // set tint color
    refreshControl addTarget:self
                      action:@selector(refreshAPI)
            forControlEvents:UIControlEventValueChanged]; // add target
    if (self.tableView != NULL) {
        // tableView will have a strong reference (and retain) refreshControl ; no need to have it be its own property
        self.tableView.refreshControl = refreshControl
    } else {
        NSLog(@"suprise!  self.tableView is null");
    }
}

และคุณควรเรียก "endRefreshing" เสมอเมื่อค่าเปลี่ยนแปลง (หรืออัปเดต) ก่อนหน้านี้คุณจะโทรหาก็ต่อเมื่อ isNetAvailable เป็นเท็จเท่านั้น

-(void)refreshAPI{

    if ([APP_DELEGATE isNetAvailable]) {
        [self fetchAPI];
    }

    [self.tableView.refreshControl endRefreshing]; //end refreshing
}
person Michael Dautermann    schedule 17.05.2018
comment
สวัสดี Michael ฉันกำลังเรียก endRefreshing ภายใน API Callbacks ของฉัน - person Amit Majumdar; 17.05.2018
comment
การเรียกกลับ API นั้นไม่รวมอยู่ในโค้ดตัวอย่างที่คุณตั้งไว้ในคำถามเดิมหรือไม่ - person Michael Dautermann; 17.05.2018
comment
ไม่ ไมเคิล มันอยู่ในวิธี fetchAPI และฉันก็ลองใช้รหัสของคุณเช่นกัน แต่ก็ยังใช้ไม่ได้กับ iPhone X มันใช้งานได้ดีกับอุปกรณ์อื่นๆ มันแปลกจริงๆ - person Amit Majumdar; 17.05.2018
comment
หากคุณตั้งค่าเบรกพอยต์ใน Xcode refreshAPI และ fetchAPI จะถูกเรียกหรือไม่ คุณสามารถวางเบรกพอยต์ที่ endRefreshing แล้วมันจะชนบน iPhoneX ได้ไหม - person Michael Dautermann; 17.05.2018
comment
ไม่ ไมเคิล วิธีการเลือกไม่ได้รับการเรียกเลย ฉันลากหน้าจอลงครึ่งหนึ่งต่อไป แต่ก็ไม่ได้ทำอะไรเลย - person Amit Majumdar; 17.05.2018
comment
ตัวควบคุมการรีเฟรชปรากฏขึ้นหรือไม่? - person Michael Dautermann; 17.05.2018
comment
ใช่ มันปรากฏตามปกติ แต่เมื่อลาก มันจะหมุนไปยังมุมหนึ่ง แต่ไม่มีการตอบสนองการสั่นหรือเรียกวิธีการเลือก - person Amit Majumdar; 17.05.2018