xib가있는 사용자 지정 UITableViewCell이 하나 있습니다.사용자 지정 UITableViewCell XIB는 스크롤 한 후 행을 반복합니다.
ProductCell
Tableview와 함께 또 다른 viewcontroller.
이제 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가 아니지만 별도로 제공됩니다.
또한 ProductCell의 .m 파일에서 셀을 기본 상태로 되돌릴 수있는'prepareForReuse'를 구현할 수 있습니다. – BreadicalMD
여기에서 반복되는 셀의 의미는 50 행입니다. 먼저 7 행을 표시합니다. 일단 스크롤을 시작하면 동일한 인스턴스가 반환됩니다. 적절한 값을 설정할 수 없습니다. 이 인스턴스를 참조하십시오 : 0x7f9d9b804b90 7 행을 반복합니다. –
네, 그런 일이 일어날 것입니다. 왜 스테퍼와 체크 박스에 적절한 값을 설정할 수 없다는 뜻입니까? 그들을 위해 아울렛이 있습니까? – JoeFryer