2013-11-24 43 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

相關問題