我想我现在真的很接近,但我错过了一些东西。如果我在返回 tableView:cellForRowAtIndexPath 方法中的单元格之前中断,则单元格包含正确的数据。但它没有出现在表格中。我我假设我的 UITableView 没有正确连接到 UIViewController。
这是我的自定义单元格:SCCustomerTableCell.h
#import <UIKit/UIKit.h>
#import "SCCustomer.h"
@interface SCCustomerTableCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *companyLabel;
-(void)configureCellWithCustomer:(SCCustomer *)customer;
@end
SCCustomerTableCell.m
#import "SCCustomerTableCell.h"
@implementation SCCustomerTableCell
-(void)configureCellWithCustomer:(SCCustomer *)customer
{
self.companyLabel = [[UILabel alloc] init];
self.companyLabel.text = [customer dbaName];
}
@end
以及自定义视图控制器:SCCustomersVC.h
#import <UIKit/UIKit.h>
#import "SCCustomerTableCell.h"
#import "SCDataObject.h"
@interface SCCustomersVC : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate>
@property (strong, nonatomic) IBOutlet UITableView *customersTable;
@property SCDataObject *dataObject;
@property (nonatomic, strong) NSArray *customers;
@end
SCCustomersVC.m
#import "SCCustomersVC.h"
#import "SCSplitVC.h"
#import "SCDataObject.h"
@interface SCCustomersVC ()
@end
@implementation SCCustomersVC
@synthesize customersTable;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.customers count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomerCell";
[self.customersTable registerClass:[SCCustomerTableCell class] forCellReuseIdentifier:CellIdentifier];
SCCustomerTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
SCCustomer *customer = (SCCustomer *)[self.customers objectAtIndex:indexPath.row];
[cell configureCellWithCustomer:customer];
return cell;
}
编辑:我忘记了故事板连接的屏幕:
SCCustomersVC,UITableView,SCCustomerTableCell,UILabel