2017-04-06 7 views
2

을 표시 10+ 초 정도 걸립니다. 사용자가 tableview의 마지막 행을 입력하면 작업 시트에서 로그 아웃을 요청하는 메시지가 나타납니다. 이 행동에 대한 내 코드는 다음과 같습니다.액션 시트 나 테이블 뷰 컨트롤러가 내 응용 프로그램에서

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 

     switch indexPath.row { 
     case 0: 
      //.. 
     case 1: 
      //.. 
     case 2: 
      //.. 
     case 3: 

      let logOutMenu = UIAlertController(title: nil, message: "Are you sure want to logout?", preferredStyle: .actionSheet) 

      let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) 
      let logOutAction = UIAlertAction(title: "Log out", style: .default, handler: { (UIAlertAction) in 
       print("sign out") 
      }) 

      logOutMenu.addAction(cancelAction) 
      logOutMenu.addAction(logOutAction) 

      self.present(logOutMenu, animated: true, completion: nil) 
     default: break 

     } 
    } 

모든 것이 제대로 작동하지만 작동 시트가 이상합니다. 액션 시트를 표시하는 데 약 10 초 (또는 그 이상)가 소요됩니다. 실제 장치에서도 동일한 동작이 나타났습니다. 내가 뭘 잘못하고있어?

+3

은 UI 업데이트를 "느린 일어날 수있는"더 이상 시간을 혼동 얻는 동시에, 그렇지 않으면이 두 애니메이션 애니메이션없이 인덱스 경로에 선택 해제 행을 호출해야 주 스레드. 'present'에 중단 점을 놓고 실행중인 스레드를 확인하십시오. –

+0

@AshleyMills 좋은 지적. –

+0

현재 중단 점을 넣었고 주 스레드에서 실행중인 메서드는 tableView (UITableView, didSelectRowAt indexPath : IndexPath)입니다. –

답변

3

당신은 자주 당신이 떨어져 일을하고 나타냅니다

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 

    switch indexPath.row { 
    case 0: 
     //.. 
    case 1: 
     //.. 
    case 2: 
     //.. 
    case 3: 

     let logOutMenu = UIAlertController(title: nil, message: "Are you sure want to logout?", preferredStyle: .actionSheet) 

     let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) 
     let logOutAction = UIAlertAction(title: "Log out", style: .default, handler: { (UIAlertAction) in 
      print("sign out") 
     }) 

     logOutMenu.addAction(cancelAction) 
     logOutMenu.addAction(logOutAction) 

     self.present(logOutMenu, animated: true, completion: nil) 
     // Deselect your row it will fix it 
     tableView.deselectRow(at: indexPath, animated: false) 
    default: break 

    } 
}