Reputation: 174
I set the identifier in in the storyboard file and my code is:
@interface SLSpuriosCorrelationsTableViewController ()
@property (strong, nonatomic) SLDataSourceObject* dataSource;
@end
@implementation SLSpuriosCorrelationsTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
_dataSource = [[SLDataSourceObject alloc] initWithDefaultValues];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _dataSource.dataBankURLs[1].count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SLSpuriosCorrelationsTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"reuseableCustomCell" forIndexPath:indexPath];
if (!cell) {
cell = [[SLSpuriosCorrelationsTableViewCell alloc] initWithRow:indexPath.row];
}
return cell;
}
I was told that if the class and the identifier are set inside the main storyboard file registering is not needed.
the custom cell class:
@interface SLSpuriosCorrelationsTableViewCell ()
@property (weak, nonatomic) SLDataSourceObject* dataSource;
@end
@implementation SLSpuriosCorrelationsTableViewCell
- (SLSpuriosCorrelationsTableViewCell*)initWithRow:(NSUInteger)row {
self = [super init];
_row = row;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSURL* imageURL = [[NSURL alloc] initWithString:[_dataSource.dataBankURLs[1] allValues][_row]];
NSData* imageAsData = [[NSData alloc] initWithContentsOfURL:imageURL];
UIImage* image = [[UIImage alloc] initWithData:imageAsData];
dispatch_async(dispatch_get_main_queue(), ^{
self.imageViews.image = image;
});
});
return self;
}
but i still get right after dequeueReusableCellWithIdentifier
is called
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier reuseableCustomCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
Upvotes: 0
Views: 93
Reputation: 4585
You get that error, because you put SLSpuriosCorrelationsTableViewCell
not in SLSpuriosCorrelationsTableViewController
, but in SLSettingsTableViewController
Upvotes: 0
Reputation: 82759
try this
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerNib:[UINib nibWithNibName:@"SLSpuriosCorrelationsTableViewCell" bundle:nil]
forCellWithReuseIdentifier:@"reusableCustomCell"];
}
and call like
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"reuseableCustomCell";
SLSpuriosCorrelationsTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(!cell)
{
cell = [[SLSpuriosCorrelationsTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.xxx.text = [yourarrayNam objectAtIndex:indexpath.row];
return cell;
}
Upvotes: 1