加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – UIPickerView导致崩溃

发布时间:2020-12-14 18:06:23 所属栏目:百科 来源:网络整理
导读:每当我尝试在我的应用程序中选择UIPickerView时它就会崩溃. 我已经实现了所有委托方法但收到此错误: 2013-01-15 13:57:56.176 tracker[16142:c07] *** Assertion failure in -[UITableViewRowData rectForRow:inSection:],/SourceCache/UIKit_Sim/UIKit-237
每当我尝试在我的应用程序中选择UIPickerView时它就会崩溃.

我已经实现了所有委托方法但收到此错误:

2013-01-15 13:57:56.176 tracker[16142:c07] *** Assertion failure in -[UITableViewRowData rectForRow:inSection:],/SourceCache/UIKit_Sim/UIKit-2372/UITableViewRowData.m:1630
2013-01-15 13:57:56.177 tracker[16142:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',reason: 'request for rect at invalid index path (<NSIndexPath 0x918c700> 2 indexes [0,0])'
*** First throw call stack:
(0x1c97012 0x10d4e7e 0x1c96e78 0xb6af35 0x2050c0 0xc892e 0x457fc6 0x457eba 0x7ba5d 0x7e03b 0x2e689a 0x2e59db 0x2e711f 0x2e9d6d 0x2e9cec 0x2e1a68 0x4efc2 0x4f4a3 0x2d3aa 0x1ecf8 0x1bf2df9 0x1bf2ad0 0x1c0cbf5 0x1c0c962 0x1c3dbb6 0x1c3cf44 0x1c3ce1b 0x1bf17e3 0x1bf1668 0x1c65c 0x29bd 0x28e5 0x1)
libc++abi.dylib: terminate called throwing an exception

以下是实现的委托方法:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {

    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { 
    return [classes count];
}


- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [classes objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    NSLog(@"Selected Class: %@. Index of selected color: %i",[classes objectAtIndex:row],row);
}

‘classes’是一个NSMutableArray.

以下是视图的连线方式:

受控视图称为MemberViewController.

我的接口声明包含以下内容:

@interface MemberViewController : UIViewController <UIPickerViewDataSource,UIPickerViewDelegate>

我究竟做错了什么?

谢谢.

解决方法

我的应用程序遇到了类似的问题. IIRC,作为数据源的数组已经被声明为弱,它被释放,当收到didSelectRow时,数组计数为0(声明它强有力地解决了这个问题).正如Rohan Kapur所指出的,有一个与从该方法返回0相关的错误.

我建议在numberOfRowsInComponent和didSelectRow的开头记录数组计数,以确保“类”真正包含您期望的内容.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读