【发布时间】:2018-02-26 11:05:37
【问题描述】:
我需要帮助了解我的控制台返回错误的原因:
** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法在包中加载 NIB:“NSBundle (已加载)”,名称为“MyListingsTableViewCell” ** 首先抛出调用堆栈:...
我是使用这些原型单元格和表格的新手,我将附上下面的代码。感谢您提供的任何支持。
实现原型单元的视图控制器代码如下:
#import "MyListings.h"
@interface MyListings ()
@property (weak, nonatomic) IBOutlet UIButton *createListingButton;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end
@implementation MyListings
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"MyListingsTableViewCell"];
UINib *nib1 = [UINib nibWithNibName:@"MyListingsTableViewCell" bundle:nil];
[self.tableView registerNib:nib1 forCellReuseIdentifier:@"MyListingsTableViewCell"];
titles = [[NSArray alloc]initWithObjects:@"1",@"2", nil];
currentBids = [[NSArray alloc]initWithObjects:@"3",@"4", nil];
stillAvailables = [[NSArray alloc]initWithObjects:@"5",@"6", nil];
_createListingButton.layer.cornerRadius = 8;
_createListingButton.layer.borderWidth = 1.5f;
_createListingButton.layer.borderColor = [UIColor whiteColor].CGColor;
[_createListingButton addTarget:self action:@selector(createListingButtonHighlightBorder) forControlEvents:UIControlEventTouchDown];
[_createListingButton addTarget:self action:@selector(createListingButtonUnhighlightBorder) forControlEvents:UIControlEventTouchUpInside];
[_createListingButton addTarget:self action:@selector(createListingButtonUnhighlightBorder) forControlEvents:UIControlEventTouchDragExit];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)createListingButtonHighlightBorder
{
_createListingButton.layer.borderColor = [UIColor colorWithRed:0.61 green:0.00 blue:0.02 alpha:1.0].CGColor;
}
- (void)createListingButtonUnhighlightBorder
{
_createListingButton.layer.borderColor = [UIColor whiteColor].CGColor;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [titles count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyListingsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyListingsTableViewCell" forIndexPath:indexPath];
[cell updateCellWithTitle:[titles objectAtIndex:indexPath.row] currentBid:[currentBids objectAtIndex:indexPath.row] stillAvailable:[stillAvailables objectAtIndex:indexPath.row]];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
Prototype Cell 类:
- (void)awakeFromNib
{
[super awakeFromNib];
// Initialization code
}
- (void)updateCellWithTitle:(NSString *)title currentBid:(NSString *)bid stillAvailable:(NSString *)available
{
self.titleLabel.text = title;
self.currentBidLabel.text = bid;
self.stillAvailableLabel.text = available;
self.editLabel.text = @"Press to edit";
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
【问题讨论】:
-
我不认为它是那个帖子的重复,我们正在尝试找到两种不同故障的解决方案,它们都与原型单元相关联。因此,总而言之,我们的问题不同,因此理论上我们的解决方案也应该不同。
标签: ios objective-c xcode uitableview