Ios 标签未在UITableView中正确实现,为什么?
我有一个tableView,它应该填充一个Ios 标签未在UITableView中正确实现,为什么?,ios,objective-c,xcode,uitableview,Ios,Objective C,Xcode,Uitableview,我有一个tableView,它应该填充一个NSMutableArray。这在没有定制原型的情况下运行良好UITableViewCell。我有一个自己的单元格文件,名为SimpleTableCell。我的故事板中的原型单元分配了这个类。内容 SimpleTableCell.h: #import <UIKit/UIKit.h> @interface SimpleTableCell : UITableViewCell @property (nonatomic, weak) IBOutle
NSMutableArray
。这在没有定制原型的情况下运行良好UITableViewCell
。我有一个自己的单元格文件,名为SimpleTableCell
。我的故事板中的原型单元分配了这个类。内容
SimpleTableCell.h:
#import <UIKit/UIKit.h>
@interface SimpleTableCell : UITableViewCell
@property (nonatomic, weak) IBOutlet UILabel *nameLabel;
@property (nonatomic, weak) IBOutlet UILabel *moreInfoLabel;
@end
这再次控制了
CargoViewController.m(仅添加相关部件)
我的问题是:
在对象UITableViewCell
根据我的故事板,这是错误的(?)
为了进一步了解,在我实现原型单元之前,该表已经运行了。在我使用默认值之前。
错误触发器:
#pragma mark -
#pragma mark PickerView DataSource
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return [boatOwners count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
return [boatOwners objectAtIndex:row];
}
#pragma mark -
#pragma mark PickerView Delegate
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
NSString *boatsFromOwner = [boatOwners objectAtIndex:[shipOwners selectedRowInComponent:0]];
//if(boatsForOwner) {[boatsForOwner release]; boatsForOwner = nil;}
boatsForOwner = [[NSMutableArray alloc] init];
if ([boatsFromOwner isEqualToString:@"Owner1"]) {
[self.boatsForOwner addObject:@"Titanic1"];
[self.boatsForOwner addObject:@"Titanic2"];
[self.boatsForOwner addObject:@"Titanic3"];
[self.boatsForOwner addObject:@"Titanic4"];
[self.boatsForOwner addObject:@"Titanic5"];
[self.boatsForOwner addObject:@"Titanic6"];
[self.boatsForOwner addObject:@"Titanic7"];
}
NSLog(@"%@",boatsFromOwner);
[boatsTableView reloadData];
}
更改此行:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
为此:
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
顺便说一句,当使用故事板tableView:dequeueReusableCellWithIdentifier:
时,将永远不会返回nil
更改此行:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
为此:
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
顺便说一下,当使用故事板tableView:dequeueReusableCellWithIdentifier:
时,将永远不会返回nil
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
试着换成
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
试着换成
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
如果它从未返回
nil
我应该如何实现该单元呢?+当我按照您所说的那样执行时,这个LNG[44650:c07]***在-[UITableView\u configureCellForDisplay:forIndexPath:],/SourceCache/UIKit\u Sim/UIKit-2372/UITableView.m:5471 LNG[44650:c07]中的断言失败***由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因是:“UITableView数据源必须从tableView返回单元格:cellForRowAtIndexPath:”
。修复?你不必担心实例化,iOS会帮你做的。我错过了我之前答案中的类型转换,现在尝试一下,包括它。我仍然得到这个错误。我用我在原始帖子底部添加的代码选择数组的内容,这就是崩溃发生的时候。你知道为什么吗?(谈到错误,我之前键入了两条注释)如果它从未返回nil
我应该如何实现该单元格?+当我按照您所说的那样做时,这个LNG[44650:c07]***在-[UITableView\u configureCellForDisplay:forindexath:],/SourceCache/UIKit\u Sim/UIKit-2372/UITableView.m:5471 LNG[44650:c07]中断言失败***由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因是:“UITableView数据源必须从tableView返回单元格:cellForRowAtIndexPath:”
。修复?你不必担心实例化,iOS会帮你做的。我错过了我之前答案中的类型转换,现在尝试一下,包括它。我仍然得到这个错误。我用我在原始帖子底部添加的代码选择数组的内容,这就是崩溃发生的时候。你知道为什么吗?(谈论我在两个评论前输入的错误)