【发布时间】:2013-11-24 01:17:30
【问题描述】:
我可能找错了树,但我试图在更新到 ios7 的项目中复制我为 ios5 编写的功能。
我已经复制并粘贴了代码,我收到了这个错误
*** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-2903.23/UITableView.m:5261
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier TableView - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(0x30829f4b 0x3ac6a6af 0x30829e25 0x311d1fe3 0x3310891f 0x11bebf 0x330cea5b 0x33076e7d 0x33076699 0x32f9cda3 0x32c23c6b 0x32c1f47b 0x32c1f30d 0x32c1ed1f 0x32c1eb2f 0x32c1885d 0x307f51cd 0x307f2b71 0x307f2eb3 0x3075dc27 0x3075da0b 0x35484283 0x33001049 0x81597 0x7b558)
除了我检查 xib 时,一切都与另一个控制器相同
工作一:
崩溃一个:
不同之处在于没有引用插座 tableCell -> 文件的所有者
怎么样?为什么?
这是代码以防万一
Viewcontroller.h
#import <UIKit/UIKit.h>
#import "blogCellVC.h"
@interface BlogsListingiPhoneVC : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
NSArray *blogsListing;
UITableView *tableView;
IBOutlet blogCellVC *tableCell;
}
Viewcontroller.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIndentifier = @"MyCell";
blogCellVC *cell = (blogCellVC *)[self.tableView dequeueReusableCellWithIdentifier:MyIndentifier forIndexPath:indexPath];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"blogCellVC" owner:self options:nil];
cell = tableCell;
}
blogsListingModel *info = [_blogsListing objectAtIndex:indexPath.row];
if (info.blogActive == 0)
{
[cell cellHead:info.blogName];
[cell cellHeadCol:[UIColor lightGrayColor]];
[cell cellIcon:@"blank.png"];
}else {
[cell cellHead:info.blogName];
[cell cellHeadCol:[UIColor blackColor]];
[cell cellIcon:@"tick.png"];
}
return cell;
}
Customcell.h
#import <UIKit/UIKit.h>
@interface blogCellVC : UITableViewCell {
IBOutlet UILabel *cellHead;
IBOutlet UIImageView *cellIcon;
}
- (void)cellHead:(NSString *)_text;
- (void)cellIcon:(NSString *)_text;
- (void)cellHeadCol:(UIColor *)aCol;
@end
Customcell.m
#import "blogCellVC.h"
@interface blogCellVC ()
@end
@implementation blogCellVC
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code.
}
return self;
}
- (void)cellHead:(NSString *)_text {
cellHead.text = _text;
}
- (void)cellHeadCol:(UIColor *)aCol {
cellHead.textColor = aCol;
//cellStandfirst.textColor = aCol;
}
- (void)cellIcon:(NSString *)_text {
cellIcon.image = [UIImage imageNamed:_text];
}
- (void)dealloc {
[super dealloc];
}
@end
PS。我已将身份检查器中文件所有者的自定义类设置为“blogCellVC”,并将属性检查器中的标识符设置为“MyCell”
【问题讨论】:
-
我在这里找到了一个解决方案:stackoverflow.com/questions/17875353/… 但它仍然没有解释为什么它在一个地方而不是另一个地方工作......
标签: ios iphone objective-c