我有動態TableView,原型單元格中有CollectionView。我創建了UITableViewCell的子類併爲TableView原型單元添加了Custom單元。此外,我還將UICollectionVeiwCell添加爲CollectionView的CustomCell。動態TableView與原型單元格中的CollectionView
它是什麼樣子的故事板:
代碼下面,我使用的是創建我的場景:
//-=-=-=-==-=-=--==-=-=-=-=-=-=-=-=--=-=-=-TableView methods-=-=-=-=--=-=-=-=-=-=-=-=
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 15;
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
myCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell) {
cell = [[myCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
return cell;
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-==-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-==
//-=-=-=-==-=-=--==-=-=-=-=-=-=-=-=--=-=-=-CollectionView methods-=-=-=-=--=-=-=-=-=-=-=-=
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 7;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString* cellIdentifier = @"CVCell";
CVCustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
if (indexPath.row == 0) {
cell.cellTxtFld.text =[NSString stringWithFormat:@"%ld", (long)indexPath.row];
}
if (indexPath.row == 1) {
cell.cellTxtFld.text =[NSString stringWithFormat:@"%ld", (long)indexPath.row];
}
if (indexPath.row == 2) {
cell.cellTxtFld.text =[NSString stringWithFormat:@"%ld", (long)indexPath.row];
}
if (indexPath.row == 3) {
cell.cellTxtFld.text =[NSString stringWithFormat:@"%ld", (long)indexPath.row];
}
if (indexPath.row == 4) {
cell.cellTxtFld.text =[NSString stringWithFormat:@"%ld", (long)indexPath.row];
}
if (indexPath.row == 5) {
cell.cellTxtFld.text =[NSString stringWithFormat:@"%ld", (long)indexPath.row];
}
if (indexPath.row == 6) {
cell.cellTxtFld.text [email protected]"LAST";
}
return cell;
}
它是如何看起來像在模擬器:
我的問題是,我怎樣才能直接訪問每個collectionView?例如,我有15個數組,我希望第一個collectionView(在第一個TableView的行中)由0-index,second-1索引等等初始化。我怎樣才能做到這一點?
請問您能更具體嗎? – daleijn
檢查我的編輯... –
您的建議導致編譯失敗。我通過簡單和愚蠢的方式 - 在CellForItemForIndexPath中使用計數器。但我不知道我可以通過我的方式爲某些TextField獲取textField.text。你可以幫我嗎? – daleijn