2012-10-06 49 views
0

我正在做一个SplitViewController与DetailView和MasterView中的TableViewController。NSInternalInconsistencyException错误UITableViewController

我在控制台中这条消息时,我尝试运行:

2012-10-06 16:42:05.304 BaylorNotes7[3040:c07] *** Assertion failure in -[UITableView  _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:5471 
2012-10-06 16:42:05.306 BaylorNotes7[3040:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' 

的问题是在DetailViewController.m:

#import "DetailViewController.h" 
#import "NSString+HTML.h" 

typedef enum { SectionHeader, SectionDetail } Sections; 
typedef enum { SectionHeaderTitle, SectionHeaderDate, SectionHeaderURL } HeaderRows; 
typedef enum { SectionDetailSummary } DetailRows; 

@implementation DetailTableViewController 

@synthesize item, dateString, summaryString; 

#pragma mark - 
#pragma mark Initialization 

- (id)initWithStyle:(UITableViewStyle)style { 
if ((self = [super initWithStyle:style])) { 

} 
return self; 
} 

#pragma mark - 
#pragma mark View lifecycle 

- (void)viewDidLoad { 

// Super 
[super viewDidLoad]; 



// Summary 
if (item.summary) { 
    self.summaryString = [item.summary stringByConvertingHTMLToPlainText]; 
} else { 
    self.summaryString = @"[No Summary]"; 
} 

} 

#pragma mark - 
#pragma mark Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
// Return the number of sections. 
return 2; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
// Return the number of rows in the section. 
switch (section) { 
    case 0: return 1; 
    default: return 1; 
} 
} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

UITableViewCell *cell = [tableView 
         dequeueReusableCellWithIdentifier:@"DetailCell"]; 

// Display 
cell.textLabel.textColor = [UIColor blackColor]; 
cell.textLabel.font = [UIFont systemFontOfSize:15]; 
if (item) { 

    // Item Info 
    NSString *itemTitle = item.title ? [item.title stringByConvertingHTMLToPlainText] : @"[No Title]"; 

    // Display 
    switch (indexPath.section) { 
     case SectionHeader: { 

      // Header 
      switch (indexPath.row) { 
       case SectionHeaderTitle: 
        cell.textLabel.font = [UIFont fontWithName:@"Times New Roman" size:20]; 
        cell.textLabel.text = itemTitle; 
        break; 
      } 
      break; 

     } 
     case SectionDetail: { 

      // Summary 
      cell.textLabel.text = summaryString; 
      cell.textLabel.numberOfLines = 100; // Multiline 
      cell.textLabel.font = [UIFont fontWithName:@"Times New Roman" size:20]; 
      break; 

     } 
    } 
} 

return cell; 

} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
if (indexPath.section == SectionHeader) { 

    // Regular 
    return 60; 

} else { 

    // Get height of summary 
    NSString *summary = @"[No Summary]"; 
    if (summaryString) summary = summaryString; 

    CGSize s = [summary sizeWithFont:[UIFont systemFontOfSize:20] 
        constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT) // - 40 For cell padding 

         lineBreakMode:UILineBreakModeWordWrap]; 

    return s.height; // Add padding 

} 
} 

#pragma mark - 
#pragma mark Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

// Open URL 
if (indexPath.section == SectionHeader && indexPath.row == SectionHeaderURL) { 
    if (item.link) { 
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:item.link]]; 
    } 
} 

// Deselect 
[self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 

} 

@end 

我敢肯定问题出在什么地方表格声明。如果有人想知道,我遵循MWFeedParser教程来获得这个。任何帮助表示赞赏!

回答

0

在此呼吁:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailCell"]; 

你忘了零检测细胞,而是将它分配是这样的:

if(cell == nil { 
    cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault 
            reuseIdentifier: cellIdentifier ] autorelease]; 
} 
相关问题