【发布时间】:2015-02-07 09:42:07
【问题描述】:
我有一个带有 xib 的自定义 UITableViewCell。
产品单元
还有另一个带有 Tableview 的视图控制器。
现在我想将 Cell 添加到 tableview 中。
这是我的代码。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tblList.dataSource = self;
[self.tblList registerNib:[UINib nibWithNibName:@"ProductCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MyIdentifierList"];
//other code lines apart from tableview.
}
TableView 数据源
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.aryData count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100.0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ProductCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifierList"];
NSDictionary *dict = [self.aryData objectAtIndex:indexPath.row];
cell.lblProductName.text = [dict objectForKey:@"Product"];
cell.tag = indexPath.row;
NSLog(@"CELL : %@",cell);
return cell;
}
您将看到该实例重复的控制台数据。 (它会导致单元格的复选框和单元格的 UIstepper 值出现问题,它们是单元格的子视图)。
2014-12-09 18:45:43.619 RetailCheckOut[4777:132965] CELL : <ProductCell: 0x7f9d9b804b90; baseClass = UITableViewCell; frame = (0 0; 320 80); autoresize = RM+BM; layer = <CALayer: 0x7f9d994b6330>>
2014-12-09 18:45:43.622 RetailCheckOut[4777:132965] CELL : <ProductCell: 0x7f9d99663780; baseClass = UITableViewCell; frame = (0 0; 320 80); autoresize = RM+BM; tag = 1; layer = <CALayer: 0x7f9d99664b90>>
2014-12-09 18:45:43.625 RetailCheckOut[4777:132965] CELL : <ProductCell: 0x7f9d996a5870; baseClass = UITableViewCell; frame = (0 0; 320 80); autoresize = RM+BM; tag = 2; layer = <CALayer: 0x7f9d996a56b0>>
2014-12-09 18:45:43.628 RetailCheckOut[4777:132965] CELL : <ProductCell: 0x7f9d9b817e50; baseClass = UITableViewCell; frame = (0 0; 320 80); autoresize = RM+BM; tag = 3; layer = <CALayer: 0x7f9d9b817c90>>
2014-12-09 18:45:43.630 RetailCheckOut[4777:132965] CELL : <ProductCell: 0x7f9d9b81e810; baseClass = UITableViewCell; frame = (0 0; 320 80); autoresize = RM+BM; tag = 4; layer = <CALayer: 0x7f9d9b81e650>>
2014-12-09 18:45:43.633 RetailCheckOut[4777:132965] CELL : <ProductCell: 0x7f9d9b825140; baseClass = UITableViewCell; frame = (0 0; 320 80); autoresize = RM+BM; tag = 5; layer = <CALayer: 0x7f9d9b824fd0>>
2014-12-09 18:45:54.978 RetailCheckOut[4777:132965] CELL : <ProductCell: 0x7f9d996a7400; baseClass = UITableViewCell; frame = (0 0; 320 80); autoresize = RM+BM; tag = 6; layer = <CALayer: 0x7f9d996b4520>>
2014-12-09 18:45:55.241 RetailCheckOut[4777:132965] CELL : <ProductCell: 0x7f9d9b804b90; baseClass = UITableViewCell; frame = (0 0; 375 100); hidden = YES; autoresize = W; tag = 7; layer = <CALayer: 0x7f9d994b6330>>
2014-12-09 18:45:56.824 RetailCheckOut[4777:132965] CELL : <ProductCell: 0x7f9d99663780; baseClass = UITableViewCell; frame = (0 100; 375 100); hidden = YES; autoresize = W; tag = 8; layer = <CALayer: 0x7f9d99664b90>>
2014-12-09 18:45:57.045 RetailCheckOut[4777:132965] CELL : <ProductCell: 0x7f9d996a5870; baseClass = UITableViewCell; frame = (0 200; 375 100); hidden = YES; autoresize = W; tag = 9; layer = <CALayer: 0x7f9d996a56b0>>
ProductCell 类 xib 不在 Storyboard 中,而是在单独的。
【问题讨论】:
标签: iphone uitableview storyboard objective-c-blocks