詳細を表示するために、クリックでセルを拡張する必要があるアプリケーションを実行しています。カスタムセルを使用して、UItableview に追加しました。セルをクリックすると正常にアニメーション化されて下に移動し、もう一度クリックすると上に移動します。これは、セルの高さを変更することで行われます。実際のカスタム セル サイズは、通常表示されるセルよりも大きくなります。セルをクリックすると、セル全体が表示されます。私が抱えている唯一の問題は、データのオーバーフローです。セルが選択されていない場合、これらのデータは非表示にする必要があります。選択されている場合にのみ、これらのデータが表示されます。
別のアーティカルを参照しましたが、カラー設定の境界を変更しようとしましたが、うまくいきませんでした。この質問iphone uitablecellview overflowで尋ねられたのと同じ種類の問題があり、答えを試しましたが、うまくいきませんでした。
私が必要とするのは、拡張されていないときにカスタムセルの下部を非表示にし、拡張されたときに表示する方法です...!
これらは私のスクリーンショットです
ロードされ
たとき セルをクリックした
とき] 2番目
のセルをクリックしたとき すでに展開されているセルをクリックしたとき これらは私が使用したコードスニップです....
// Declaring the SearchResultTable.
CGRect filterFrame = CGRectMake(0,31, 320, 400);
self.searchResultTable = [[UITableView alloc] initWithFrame:filterFrame];
self.searchResultTable.dataSource = self;
self.searchResultTable.delegate = self;
self.searchResultTable.backgroundColor = [UIColor whiteColor];
self.searchResultTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
self.searchResultTable.separatorColor = [UIColor lightGrayColor];
[self.view addSubview:self.searchResultTable];
//Adding cells
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ExpandedSearchResultTableCell";
ExpandedSearchResultTableCell *cell = (ExpandedSearchResultTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell.contentView.clipsToBounds = YES;
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ExpandedSearchResultTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.productNameLable.text = @"Only this should be shown";
cell.productListLabel.text = @"This Should be hidden.. Only shown when expanded";
cell.productApplicationLable.text=@"This Should be hidden.. Only shown when expanded";
cell.productTargetLable.text= @"This Should be hidden.. Only shown when expanded";
cell.productQuantityLable.text=@"This Should be hidden.. Only shown when expanded";
cell.productReactivityLable.text=@"This Should be hidden.. Only shown when expanded";;
return cell;
}
//on click event
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Deselect cell
[tableView deselectRowAtIndexPath:indexPath animated:TRUE];
// Toggle 'selected' state
BOOL isSelected = ![self cellIsSelected:indexPath];
// Store cell 'selected' state keyed on indexPath
NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
[selectedIndexes setObject:selectedIndex forKey:indexPath];
// This is where magic happens...
[searchResultTable beginUpdates];
[searchResultTable endUpdates];
}
//Getting the height depending on expanded or not
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// If our cell is selected, return double height
if([self cellIsSelected:indexPath]) {
return kCellHeight * 3.0;
}
// Cell isn't selected so return single height
return kCellHeight;
}