为什么uipickerview错误:尝试调用-CellForrowatIndExpath:在更新其可见单元格过程中的表视图上?

发布于 2025-02-11 03:34:14 字数 5212 浏览 2 评论 0原文

打开uipickerview时会遇到错误。 我的Uipickerview有16个项目。

    func open_activity_picker()
{
    activity_UIPickerView = UIPickerView()

        activity_UIPickerView.delegate = self
        activity_UIPickerView.dataSource = self
        activity_UIPickerView.backgroundColor = UIColor.white
        activity_UIPickerView.setValue(UIColor.black, forKey: "textColor")
        activity_UIPickerView.autoresizingMask = .flexibleWidth
        activity_UIPickerView.contentMode = .center
        activity_UIPickerView.frame = CGRect.init(    x: 0.0, 
                                                    y: 10,       //UIScreen.main.bounds.size.height - 300, 
                                                    width: UIScreen.main.bounds.size.width, 
                                                    height: 300)
        self.view.addSubview(activity_UIPickerView)
}

func numberOfComponents(in pickerView: UIPickerView) -> Int 
{
        return 1  // total picker columns 
}


func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int 
{
    return 16
}


func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? 
{
            var activity_title = ""
            var nmbr_activity_title = ""
        switch( row )
        {
            case 0:          activity_title = "aerobics               ";      nmbr_activity_title = " 1. aerobics               "
            case 1:          activity_title = "bike (mountain)          ";      nmbr_activity_title = " 2. bike (mountain)        "
            case 2:          activity_title = "bike (street)            ";      nmbr_activity_title = " 3. bike (street)          "
            case 3:          activity_title = "calisthenics           ";      nmbr_activity_title = " 4. calisthenics           "
            case 4:          activity_title = "golf 9 holes           ";      nmbr_activity_title = " 5. golf 9 holes           "
            case 5:          activity_title = "golf 18 holes          ";      nmbr_activity_title = " 6. golf 18 holes          "
            case 6:          activity_title = "hike moderate          ";      nmbr_activity_title = " 7. hike moderate        "
            case 7:          activity_title = "hike strenuous         ";      nmbr_activity_title = " 8. hike strenuous       "
            case 8:          activity_title = "jog                    ";      nmbr_activity_title = " 9. jog                    "
            case 9:          activity_title = "karate kata";      nmbr_activity_title = "10. karate kata"
            case 10:         activity_title = "run";      nmbr_activity_title = "11. run"
            case 11:         activity_title = "stationary exercises";      nmbr_activity_title = "12. stationary exercises"
            case 12:         activity_title = "swim";      nmbr_activity_title = "13. swim"
            case 13:         activity_title = "treadmill";      nmbr_activity_title = "14. treadmill"
            case 14:         activity_title = "walk";      nmbr_activity_title = "15. walk"
            case 15:         activity_title = "woopie";      nmbr_activity_title = "16. woopie"
            default:
                handle_fault("")
        }
        activity_title = TRIM( activity_title )
        activity_title = activity_title.replacingOccurrences(of: " ", with: "_", options: .literal, range: nil)
        activity_selection_types[ row ] = activity_title 


        // Select boot default if no activity selected?
        if activity_selection_type == ""   &&   row == 0
        {
            activity_selection_type = activity_title
        }
        // row is previous user selection of activity_selection_type?
        if activity_title == activity_selection_type
        {
            activity_UIPickerView.selectRow( row, inComponent: component, animated: true)
        }

        return( TRIM( nmbr_activity_title    ))
    }

输出 - - - - - - - - - - - - - - - - - - - - - - - - - ----(对不起,stacko删除了lineFeeds)

open_activity_picker()...  

编号components:1
编号:1
numberFrowsIncomponent:16
numberFrowsIncomponent:16
numberFrowsIncomponent:16
numberFrowsIncomponent:16
numberFrowsIncomponent:16
numberFrowsIncomponent:16
编号:1
numberFrowsIncomponent:16
--------第0行Anerobics Activity_Selection_type:自行车_(山)
--------第1行自行车_(山)活动_selection_type:自行车_(山) 2022-06-27 09:53:36.183633-0700 kp_to_ios_5 [38198:1313788] [servert]试图致力于调用-cellforrowatAtindIndExpath:在表视图上,在更新其可见单元格的过程中,不允许使用该单元。在uitaiteViewAlertForcellForrowAtatIndExpathAccessDuringUpdate上进行符号断点,以在调试器中捕捉到这一点,并查看导致这种情况的原因。也许您正在尝试从表内部的表查看表查看特定行的回调?表视图:< uipickertableView:0x14802b400;帧=(9 -170.667; 675 375);不透明=否; GesturerEcognizers =< nSarray:0x2810fdb00>;; layer =< calayer:0x281ef5080>; ContentOffSet:{0,-171.6666666666666}; contentsize:{675,512}; AdjustedContentInset:{171.66666666666666,0,171.33333333333334,0}; DataSource:< uipickercolumnview:0x1475132f0;帧=(0 0; 693 300);自动化= W+TM+H; gesturerEcognizers =< nsarray:0x2810da970>;; layer =< calayer:0x281ef7ea0>>>

I get the error when I open UIPickerView.
My UIPickerView has 16 items.

    func open_activity_picker()
{
    activity_UIPickerView = UIPickerView()

        activity_UIPickerView.delegate = self
        activity_UIPickerView.dataSource = self
        activity_UIPickerView.backgroundColor = UIColor.white
        activity_UIPickerView.setValue(UIColor.black, forKey: "textColor")
        activity_UIPickerView.autoresizingMask = .flexibleWidth
        activity_UIPickerView.contentMode = .center
        activity_UIPickerView.frame = CGRect.init(    x: 0.0, 
                                                    y: 10,       //UIScreen.main.bounds.size.height - 300, 
                                                    width: UIScreen.main.bounds.size.width, 
                                                    height: 300)
        self.view.addSubview(activity_UIPickerView)
}

func numberOfComponents(in pickerView: UIPickerView) -> Int 
{
        return 1  // total picker columns 
}


func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int 
{
    return 16
}


func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? 
{
            var activity_title = ""
            var nmbr_activity_title = ""
        switch( row )
        {
            case 0:          activity_title = "aerobics               ";      nmbr_activity_title = " 1. aerobics               "
            case 1:          activity_title = "bike (mountain)          ";      nmbr_activity_title = " 2. bike (mountain)        "
            case 2:          activity_title = "bike (street)            ";      nmbr_activity_title = " 3. bike (street)          "
            case 3:          activity_title = "calisthenics           ";      nmbr_activity_title = " 4. calisthenics           "
            case 4:          activity_title = "golf 9 holes           ";      nmbr_activity_title = " 5. golf 9 holes           "
            case 5:          activity_title = "golf 18 holes          ";      nmbr_activity_title = " 6. golf 18 holes          "
            case 6:          activity_title = "hike moderate          ";      nmbr_activity_title = " 7. hike moderate        "
            case 7:          activity_title = "hike strenuous         ";      nmbr_activity_title = " 8. hike strenuous       "
            case 8:          activity_title = "jog                    ";      nmbr_activity_title = " 9. jog                    "
            case 9:          activity_title = "karate kata";      nmbr_activity_title = "10. karate kata"
            case 10:         activity_title = "run";      nmbr_activity_title = "11. run"
            case 11:         activity_title = "stationary exercises";      nmbr_activity_title = "12. stationary exercises"
            case 12:         activity_title = "swim";      nmbr_activity_title = "13. swim"
            case 13:         activity_title = "treadmill";      nmbr_activity_title = "14. treadmill"
            case 14:         activity_title = "walk";      nmbr_activity_title = "15. walk"
            case 15:         activity_title = "woopie";      nmbr_activity_title = "16. woopie"
            default:
                handle_fault("")
        }
        activity_title = TRIM( activity_title )
        activity_title = activity_title.replacingOccurrences(of: " ", with: "_", options: .literal, range: nil)
        activity_selection_types[ row ] = activity_title 


        // Select boot default if no activity selected?
        if activity_selection_type == ""   &&   row == 0
        {
            activity_selection_type = activity_title
        }
        // row is previous user selection of activity_selection_type?
        if activity_title == activity_selection_type
        {
            activity_UIPickerView.selectRow( row, inComponent: component, animated: true)
        }

        return( TRIM( nmbr_activity_title    ))
    }

OUTPUT ----------------------------------------------------- (sorry, StackO removes linefeeds)

open_activity_picker()...  

numberOfComponents: 1
numberOfComponents: 1
numberOfRowsInComponent: 16
numberOfRowsInComponent: 16
numberOfRowsInComponent: 16
numberOfRowsInComponent: 16
numberOfRowsInComponent: 16
numberOfRowsInComponent: 16
numberOfComponents: 1
numberOfRowsInComponent: 16
-------- row 0 aerobics activity_selection_type: bike_(mountain)
-------- row 1 bike_(mountain) activity_selection_type: bike_(mountain)
2022-06-27 09:53:36.183633-0700 KP_to_iOS_5[38198:1313788] [Assert] Attempted to call -cellForRowAtIndexPath: on the table view while it was in the process of updating its visible cells, which is not allowed. Make a symbolic breakpoint at UITableViewAlertForCellForRowAtIndexPathAccessDuringUpdate to catch this in the debugger and see what caused this to occur. Perhaps you are trying to ask the table view for a cell from inside a table view callback about a specific row? Table view: <UIPickerTableView: 0x14802b400; frame = (9 -170.667; 675 375); opaque = NO; gestureRecognizers = <NSArray: 0x2810fdb00>; layer = <CALayer: 0x281ef5080>; contentOffset: {0, -171.66666666666666}; contentSize: {675, 512}; adjustedContentInset: {171.66666666666666, 0, 171.33333333333334, 0}; dataSource: <UIPickerColumnView: 0x1475132f0; frame = (0 0; 693 300); autoresize = W+TM+H; gestureRecognizers = <NSArray: 0x2810da970>; layer = <CALayer: 0x281ef7ea0>>>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文