gpt4 book ai didi

ios - UIPickerView 导致崩溃

转载 作者:可可西里 更新时间:2023-11-01 05:09:43 26 4
gpt4 key购买 nike

每当我尝试在我的应用程序中选择 UIPickerView 时,它就会崩溃。

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

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

下面是实现的委托(delegate)方法:

- (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。

View 的连接方式如下:

enter image description here

控制的 View 称为 MemberViewController。

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

@interface MemberViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>

我做错了什么?

谢谢。

最佳答案

我在以前的应用程序中遇到过这个问题,我快速查找并在 Assertion failure on picker view 上找到了这个答案

这绝对是一个错误,除非 memberPicker 被声明为 UITableView 对象。

这段代码可能会修复它:

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if ([classes count] == 0)
return 1;
return [classes count];
}

顺便说一下,您在运行什么版本的 Xcode 和 iOS?

关于ios - UIPickerView 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14339505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com