不会使用存在且已设置的标识符对单元格进行出列

时间:2017-01-18 08:04:03

标签: ios objective-c uitableview exception cell

我在storyboard文件中设置了标识符,我的代码是:

@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;
}

有人告诉我,如果在主故事板文件中设置了类和标识符,则不需要注册。

自定义单元格类:

@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;
}

但在dequeueReusableCellWithIdentifier被称为

之后我仍然正确
  

由于未捕获的异常而终止应用   'NSInternalInconsistencyException',原因:'无法将单元格出列   使用标识符reuseableCustomCell - 必须注册一个nib或一个类   标识符或连接故事板'

中的原型单元格

2 个答案:

答案 0 :(得分:1)

试试这个

$('#btnSaving').click(function(){
   var myTableArray = [];

   $('#tblSavingColl tr:not(:first)').each(function () {
        var tds = $(this).find('td');

        var myDets= { collSheetNo: $('#').val(), clientNo: $(tds[0]).html() }
        myTableArray.push(myDets);
    })

    $.ajax({
        type: 'POST',
        url: '@Url.Action("SaveSavingColln", "CollectionSheetTranscation")',
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(myTableArray),
        success: function (result) {
            alert(result);
        },
        error: function () {
            alert("Error while saving Saving Collection Sheet");
        }
    });
});

并调用

   <Route path="/" component={() => (<App {...store} />)} />

答案 1 :(得分:0)

您收到该错误,因为您SLSpuriosCorrelationsTableViewCell不在SLSpuriosCorrelationsTableViewController,而在SLSettingsTableViewController