Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用';下标';突然出现了,但之前代码还在工作_Ios_Swift_Swift2_Nsarray_Uidatepicker - Fatal编程技术网

Ios 使用';下标';突然出现了,但之前代码还在工作

Ios 使用';下标';突然出现了,但之前代码还在工作,ios,swift,swift2,nsarray,uidatepicker,Ios,Swift,Swift2,Nsarray,Uidatepicker,突然,我开始出现一个错误,表示下标的使用不明确,但如果我转到git中的上一个commit,那么我发现一切都正常,我不知道会发生什么。以下是我的等级: import Foundation class NewScheduleViewController: UIViewController, UITableViewDataSource, UITableViewDelegate ,UIPickerViewDataSource,UIPickerViewDelegate { @IBOutlet w

突然,我开始出现一个错误,表示下标的使用不明确,但如果我转到git中的上一个commit,那么我发现一切都正常,我不知道会发生什么。以下是我的等级:

import Foundation
class NewScheduleViewController: UIViewController, UITableViewDataSource, UITableViewDelegate ,UIPickerViewDataSource,UIPickerViewDelegate {

    @IBOutlet weak var schedulesTable: UITableView!


    var x = 1
    var y = 0
    var z = 0
    var time1 = Int()
    var time2 = Int()
    var rowNumber = Int()
    var tagNumber = Int()
    var pickerView: UIPickerView!
    var pickerValues: NSMutableArray = []
    var startingTime = String()
    var endingTime = String()
    var daysArray = ["Monday" , "Tuesday" ,"Wednesday" ,"Thursday" ,"Friday" ,"Saturday" ,"Sunday" ];
    enum pickerComponent:Int{
        case weekday = 0
        case minutos = 1
        case meridiano = 2
    }

    var schedulesArray = NSMutableArray()
    override func viewDidLoad() {
        super.viewDidLoad()
        pickerValues = [["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"],["30","00"], ["AM", "PM"]]

        schedulesTable.delegate = self
        schedulesTable.dataSource = self
        addLeftBarButton ()

        pickerView = UIPickerView()
        pickerView.backgroundColor = UIColor.whiteColor()

        pickerView.dataSource = self
        pickerView.delegate = self

        let webServiceHandler = FetchScheduleData.init()
        webServiceHandler.fetchDataFromWebService(["doctor_id" : 7], closure: { (response:FetchScheduleListResponse) -> Void in
            if response.doctorschedule?.count == 0 {

                return;
            }
            self.schedulesArray.removeAllObjects()
            for appointmentListResponse in response.doctorschedule! {
                print( "Value of  index is \(appointmentListResponse)")
                self.schedulesArray.addObject(appointmentListResponse)
                print("Index is " ,appointmentListResponse.day_index)
            }
            self.schedulesTable.reloadData()
        })


    }

    func addLeftBarButton () {

        let myBackButton:UIButton = UIButton()
        myBackButton.addTarget(self, action: "segmentedAction:", forControlEvents: UIControlEvents.TouchUpInside)
        myBackButton.setImage(UIImage(named: "newBack.png"), forState: .Normal)
        myBackButton.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal)
        myBackButton.sizeToFit()
        let myCustomBackButtonItem:UIBarButtonItem = UIBarButtonItem(customView: myBackButton)
        self.navigationItem.leftBarButtonItem  = myCustomBackButtonItem
        let img = UIImage(named: "top-menu.jpg")
        navigationController?.navigationBar.setBackgroundImage(img, forBarMetrics: .Default)

    }

    @IBAction func segmentedAction(sender: AnyObject) {        
        self.dismissViewControllerAnimated(true, completion: nil)
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

   //functions for table

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {

        return 1

    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return daysArray.count

    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell : ScheduleCell! = tableView.dequeueReusableCellWithIdentifier("scheduleCell") as! ScheduleCell
        cell.selectionStyle = UITableViewCellSelectionStyle.None;        
        cell!.editButton.tag = indexPath.row;
        cell!.editButton.addTarget(self, action: "yourButtonClicked:", forControlEvents: UIControlEvents.TouchUpInside)        
        cell.startTime.inputView = pickerView
        cell.startTime.tag = (indexPath.row)*2 + 1
        cell.endTime.inputView = pickerView
        cell.endTime.tag = (indexPath.row)*2 + 2
        cell.startTime.addTarget(self, action: "textFieldDidChange:", forControlEvents: UIControlEvents.EditingDidBegin)
        cell.endTime.addTarget(self, action: "textFieldDidChange:", forControlEvents: UIControlEvents.EditingDidBegin)
        cell.dayLabel.text = daysArray[indexPath.row]        
        cell.startTime.userInteractionEnabled = false
        cell.endTime.userInteractionEnabled = false

        for (var i =  0 ; i < schedulesArray.count ; i++  ) {
            let scheduleDetails : FetchScheduleDetailResponse = self.schedulesArray.objectAtIndex(i) as! FetchScheduleDetailResponse
            print(scheduleDetails.day_index)
            if (Int(scheduleDetails.day_index!)  ==  indexPath.row+1 ) {
                cell.startTime.text = scheduleDetails.start_hour
                cell.endTime.text = scheduleDetails.end_hour
            }
        }                
        return cell as ScheduleCell
    }

    func textFieldDidChange (sender : UITextField) {         
        if(sender.tag % 2 == 0) {
        rowNumber = sender.tag / 2
            y = 3
        } else {
        rowNumber = (sender.tag / 2) + 1
            y = 2
        }        
         tagNumber = sender.tag        
    }

    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return pickerValues.count
    }

    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{
        return pickerValues[component].count
    }

    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {        
        return pickerValues[component][row] as? String
    }    
    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {        
        self.view.endEditing(true)        
        let indexPath = NSIndexPath(forRow: rowNumber - 1, inSection: 0)
        let  cell = self.schedulesTable.cellForRowAtIndexPath(indexPath) as! ScheduleCell                
        let weekDay2 = pickerComponent.weekday.rawValue
        let weekDay = pickerValues[weekDay2][pickerView.selectedRowInComponent(weekDay2)] as! String
        if y == 1 {
        }  else {
            let minutos2 = pickerComponent.minutos.rawValue
            let minutos = pickerValues[minutos2][pickerView.selectedRowInComponent(minutos2)] as! String
            let meridiano2 = pickerComponent.meridiano.rawValue
            let meridiano = pickerValues[meridiano2][pickerView.selectedRowInComponent(meridiano2)] as! String            
            if meridiano == "PM" {
                z = 2
            } else {
                z = 1
            }            
            if y == 2 {
                if cell.startTime.tag == tagNumber {
                    cell.startTime.text = "\(weekDay) : \(minutos)   \(meridiano)"
                        startingTime =  "\(weekDay) : \(minutos)   \(meridiano)"
                }

                if z == 2 {
                    time1 = Int(weekDay)!*60 + Int(minutos)! + 12*60
                }else{
                    time1 = Int(weekDay)!*60 + Int(minutos)!
                }
                print("time1 = \(time1)")
            }

            if y == 3 {
                if z == 2 {
                    time2 = Int(weekDay)!*60 + Int(minutos)! + 12*60
                }
                else{
                    time2 = Int(weekDay)!*60 + Int(minutos)!
                }
                if time1 >= time2 {
                }
                if ((time2 - time1) % DoctorInformation.call_duration) != 0 {
                }
                else{
                    if cell.endTime.tag == tagNumber {
                        cell.endTime.text = "\(weekDay) : \(minutos)   \(meridiano)"
                        endingTime = "\(weekDay) : \(minutos)   \(meridiano)"
                    }

                }                
                print(DoctorInformation.call_duration)
                let nd2 = time2 - time1
                let nd = (time2 - time1) % DoctorInformation.call_duration
                print("dif = \(nd2)")
                print("modulo = \(nd)")
                print("time2 = \(time2)")

            }

        }

    }


    func yourButtonClicked (sender : UIButton){
        let indexPath = NSIndexPath(forRow:  sender.tag, inSection: 0)
        let  cell = self.schedulesTable.cellForRowAtIndexPath(indexPath) as! ScheduleCell

        if sender.titleForState(UIControlState.Normal) == "Edit" {
            sender.setTitle("Done", forState: UIControlState.Normal)
            cell.startTime.userInteractionEnabled = true
            cell.endTime.userInteractionEnabled = true

        } else {
            sender.setTitle("Edit", forState: UIControlState.Normal)
            cell.startTime.userInteractionEnabled = false
            cell.endTime.userInteractionEnabled = false            
            let userDefaultData = NSUserDefaultData()
            let webServiceHandler = SetScheduleDataHandler.init()
            webServiceHandler.fetchDataFromWebServicePost(["doctor_id": userDefaultData.getDoctotId() , "start_time" : startingTime , "end_time" : endingTime , "day_index" : 1], closure: {(response:SetScheduleResponse) -> Void in
                 Alerts.showAlert("Done", alertTitle: response.Status!, viewController: self)
            })


        }

    }


    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

                return 75

        }    
}
<代码>导入基础 类NewScheduleViewController:UIViewController、UITableViewDataSource、UITableViewDelegate、UIPickerViewDataSource、UIPickerViewDelegate{ @IBOutlet弱var schedulesTable:UITableView! 变量x=1 变量y=0 var z=0 var time1=Int() var time2=Int() var rowNumber=Int() var tagNumber=Int() var pickerView:UIPickerView! var pickerValues:NSMutableArray=[] var startingTime=String() var endingTime=String() var daysArray=[“周一”、“周二”、“周三”、“周四”、“周五”、“周六”、“周日”]; 枚举选择器组件:Int{ 案例工作日=0 案例分钟数=1 案例O=2 } var schedulesArray=NSMutableArray() 重写func viewDidLoad(){ super.viewDidLoad() 选择器值=[“01”、“02”、“03”、“04”、“05”、“06”、“07”、“08”、“09”、“10”、“11”、“12”]、[“30”、“00”]、[“AM”、“PM”] schedulesTable.delegate=self schedulesTable.dataSource=self addLeftBarButton() pickerView=UIPickerView() pickerView.backgroundColor=UIColor.whiteColor() pickerView.dataSource=self pickerView.delegate=self 让webServiceHandler=FetchScheduleData.init() webServiceHandler.fetchDataFromWebService([“医生id”:7],闭包:{(响应:FetchScheduleListResponse)->中的Void 如果响应.doctorschedule?.count==0{ 返回; } self.schedulesArray.removeAllObjects() 对于appointmentListResponse.doctorschedule{ 打印(“索引值为\(任命列表响应)”) self.schedulesArray.addObject(appointmentListResponse) 打印(“索引为”,任命列表响应。日期索引) } self.schedulesTable.reloadData() }) } func addLeftBarButton(){ 让myBackButton:UIButton=UIButton() myBackButton.addTarget(self,action:“segmentedAction:”,forControlEvents:UIControlEvents.TouchUpInside) setImage(UIImage(名为:“newBack.png”),forState:.Normal) myBackButton.setTitleColor(UIColor.blueColor(),用于状态:UIControlState.Normal) myBackButton.sizeToFit()文件 让myCustomBackButtonItem:UIBarButtonItem=UIBarButtonItem(customView:myBackButton) self.navigationItem.leftBarButtonItem=myCustomBackButtonItem 让img=UIImage(名为:“top menu.jpg”) navigationController?.navigationBar.setBackgroundImage(img,forBarMetrics:.默认值) } @iAction func segmentedAction(发送方:AnyObject){ self.dismissViewControllerAnimated(真,完成:无) } 重写函数didReceiveMemoryWarning(){ 超级。我收到了记忆警告() //处置所有可以重新创建的资源。 } //表的函数 func numberOfSectionsInTableView(tableView:UITableView)->Int{ 返回1 } func tableView(tableView:UITableView,numberofrowsinssection:Int)->Int{ 返回日期array.count } func tableView(tableView:UITableView,cellForRowAtIndexPath:nsindepath)->UITableView单元格{ 让cell:ScheduleCell!=tableView.dequeueReusableCellWithIdentifier(“ScheduleCell”)作为!ScheduleCell cell.selectionStyle=UITableViewCellSelectionStyle.None; cell!.editButton.tag=indexPath.row; cell!.editButton.addTarget(self,action:“yourButtonClicked:”,forControlEvents:UIControlEvents.TouchUpInside) cell.startTime.inputView=pickerView cell.startTime.tag=(indexPath.row)*2+1 cell.endTime.inputView=pickerView cell.endTime.tag=(indexPath.row)*2+2 cell.startTime.addTarget(self,action:“textFieldDidChange:”,forControlEvents:UIControlEvents.EditingDidBegin) cell.endTime.addTarget(self,action:“textFieldDidChange:”,forControlEvents:UIControlEvents.EditingDidBegin) cell.dayLabel.text=daysArray[indexPath.row] cell.startTime.userInteractionEnabled=false cell.endTime.userInteractionEnabled=false 对于(变量i=0;iInt{ 返回pickerValues.count } func pickerView(pickerView:UIPickerView,numberOfRowsInComponent:Int)->Int{ 返回PickerValue[component]。计数 } func pickerView(pickerView:UIPickerView,titleForRow行:Int,forComponent组件:Int)->String?{ 将pickerValues[组件][行]返回为?字符串 } func pickerView(pickerView:UIPickerView,didSelectRow行:Int,不完整组件:Int){ self.view.endEditing(true) 让indexPath=NSIndexPath(forRow:rowNumber-1,第0节) 让细胞