2013-11-24 26 views
0

我可能会吠叫错误的树,但我试图复制我为ios5编写的功能已更新到ios7的项目。自定义uitablecellcant连接表格文件的所有者

我已经复制并粘贴整个代码,我得到这个错误

*** 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) 

一切都是一样的另一个控制器,其中它的工作原理除非我检查厦门国际银行

工作之一:

enter image description here

崩溃之一:

enter image description here

的区别是有没有引用出口的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”

+0

我发现了一个解决方案在这里:http://stackoverflow.com/questions/17875353/no-visible-view-in-custom-table-view-cell?rq = 1但它仍不能解释为什么它在一个地方工作,而不是另一个地方...... – JulianB

回答

0

我发现这里的解决方案:

No Visible View in Custom Table View Cell

在自定义的UITableViewCell,在身份检查指定文件的所有者的类与表视图,并覆盖的UITableView细胞与自定义类

我的错误是试图重新使用自定义类与第二视图。

为了完整性,最小代码

parent.h

#import "blogCellVC.h" 

@interface BlogsListingiPhoneVC : UIViewController <UITableViewDataSource, UITableViewDelegate> 
{ 
    UITableView *tableView; 
    IBOutlet blogCellVC *tableCell; 
} 

parent.m

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [tableView registerClass: [blogCellVC class] forCellReuseIdentifier:@"MyCell"]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *MyIndentifier = @"MyCell"; 

    blogCellVC *cell = (blogCellVC *)[self.tableView dequeueReusableCellWithIdentifier:MyIndentifier forIndexPath:indexPath]; 

    if (cell == nil) 
    { 
     cell = [[blogCellVC alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];  
    } 

    [cell cellHead:info.blogName]; 
    [cell cellHeadCol:[UIColor lightGrayColor]]; 
    [cell cellIcon:@"blank.png"]; 
    return cell; 
} 

blogCellVC.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 

blogCellVC。米

@interface blogCellVC() 

@end 

@implementation blogCellVC 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     // Initialization code. 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"blogCellVC" owner:self options:nil]; 
     self = [nib objectAtIndex:0]; 
    } 
    return self; 
} 

最后确保在厦门国际银行/故事情节,你已经把“了myCell”或任何在标识符字段在属性检查器。

这个工作在X码5,ios7

相关问题