iOS为什么我的UIPickerview方法循环?
我构建了一个简单的程序来探索CoreData关系的问题 然而,这两种方法在一个序列之后意外地循环(并且成功地到达目标iOS为什么我的UIPickerview方法循环?,ios,loops,core-data,uipickerview,Ios,Loops,Core Data,Uipickerview,我构建了一个简单的程序来探索CoreData关系的问题 然而,这两种方法在一个序列之后意外地循环(并且成功地到达目标VC)。所涉及的方法包括numberOfRowsInComponent(循环4次)和titleForRow(循环5次),在继续之前创建此NSLog输出: 2014-03-01 12:12:26.231 EntitiesAndRelationships[64785:a0b] Number of categories is 2 2014-03-01 12:12:26.233 Entit
VC
)。所涉及的方法包括numberOfRowsInComponent
(循环4次)和titleForRow
(循环5次),在继续之前创建此NSLog
输出:
2014-03-01 12:12:26.231 EntitiesAndRelationships[64785:a0b] Number of categories is 2
2014-03-01 12:12:26.233 EntitiesAndRelationships[64785:a0b] Number of categories is 2
2014-03-01 12:12:26.236 EntitiesAndRelationships[64785:a0b] Number of categories is 2
2014-03-01 12:12:26.237 EntitiesAndRelationships[64785:a0b] Number of categories is 2
2014-03-01 12:12:26.239 EntitiesAndRelationships[64785:a0b] Description of row is <WMDGCategory: 0x8a8a420> (entity: WMDGCategory; id: 0x8a8e2c0 <x-coredata://75EA0FB2-AB3F-480A-9EBE-CDA14EDEB902/WMDGCategory/p2> ; data: <fault>)
2014-03-01 12:12:26.242 EntitiesAndRelationships[64785:a0b] Description of row is <WMDGCategory: 0x8a8c110> (entity: WMDGCategory; id: 0x8a8e2d0 <x-coredata://75EA0FB2-AB3F-480A-9EBE-CDA14EDEB902/WMDGCategory/p1> ; data: <fault>)
2014-03-01 12:12:26.246 EntitiesAndRelationships[64785:a0b] Description of row is <WMDGCategory: 0x8a8a420> (entity: WMDGCategory; id: 0x8a8e2c0 <x-coredata://75EA0FB2-AB3F-480A-9EBE-CDA14EDEB902/WMDGCategory/p2> ; data: <fault>)
2014-03-01 12:12:26.247 EntitiesAndRelationships[64785:a0b] Description of row is <WMDGCategory: 0x8a8c110> (entity: WMDGCategory; id: 0x8a8e2d0 <x-coredata://75EA0FB2-AB3F-480A-9EBE-CDA14EDEB902/WMDGCategory/p1> ; data: <fault>)
2014-03-01 12:12:26.249 EntitiesAndRelationships[64785:a0b] Description of row is <WMDGCategory: 0x8a8a420> (entity: WMDGCategory; id: 0x8a8e2c0 <x-coredata://75EA0FB2-AB3F-480A-9EBE-CDA14EDEB902/WMDGCategory/p2> ; data: <fault>)
我很困惑。有人能帮忙吗
谢谢
根据reecon的回答编辑以下内容
我移动了这一行:
frc = [WMDGCategory MR_fetchAllGroupedBy:nil withPredicate:nil sortedBy:@"name" ascending:YES];
进入viewdiload
,但循环仍然存在。您的数据源和委托方法可以被调用任意次数-这不是问题
您应该假设方法:
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
或
可以在任何时间和多次调用。因此,它的实现应该是轻量级的。将提取代码移到其他位置-例如,移到viewDidLoad
。所以你只取一次。然后,当选择器从其委托请求信息时,不会导致执行不需要的获取。您的数据源和委托方法可以被调用任意次数—这不是问题。您的代码是否正常工作?是的,到目前为止,一切正常。我仍然有一些东西要实现,但我被这个小怪癖挂了。非常感谢你让我直截了当,但如果你再次收到我的来信,请不要感到惊讶!:)没问题,伙计:)我是来帮忙的。如果我的答案有帮助,你能接受并投票支持吗?:)
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;