使用Xcode 6.1,main.Storyboard
我正在处理我的书中的练习题,两个表视图,一个到另一个。我可以得到所有这两个结果:(1)它移动到第二个表但是为空(2)NSException错误如果我将代码保存在其中:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return departments.count;
}
我没有看到连接它们的是什么。在第一个中它给出了self.objects,但是用新数组复制这个格式是不行的。它与第二种情况下改变的数组大小有关吗?为什么看不到我的要求呢?
2014-11-28 19:52:22.477 oc11p5[33625:1199663] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:6116
2014-11-28 19:52:22.479 oc11p5[33625:1199663] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
由于这是导致问题的原因,我只是放置这两个文件:
#import "TableViewController.h"
#import "MasterViewController.h"
@interface TableViewController ()
@end
@implementation TableViewController
@synthesize selectionH;
@synthesize departments;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if (selectionH==0){
departments = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", nil];
}
else if (selectionH == 1){
departments = [NSMutableArray arrayWithObjects:@"A", @"B", @"C", @"D", @"E", nil];
}
else{
departments = [NSMutableArray arrayWithObjects:@"Red", @"Green", @"Yellow", @"Blue", nil];
}
}
- (void)insertNewObject:(id)sender {
[departments insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
//vCausing Issue
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return departments.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NSDate *object = departments[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
@end
和.h:
#import <UIKit/UIKit.h>
@interface TableViewController : UITableViewController
@property (strong, nonatomic) id detailItem;
@property int selectionH;
@property NSMutableArray * departments;
@end
答案 0 :(得分:0)
确保您的小区标识符已设置。例如,您可以将其设置为Departments Cell,然后代码将如下所示
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Departments Cell" forIndexPath:indexPath];
//NSDate *object = departments[indexPath.row]; There is an issue with this code
cell.textLabel.text = departments[indexPath.row]; //you can set the text this way
return cell;
}
如果有效,请回复。