Select TableView 中的一个单元格并更改了大小
Select a Cell in a TableView and changed size
我需要设置我的 UITableView
单元格,当我 select 一个单元格的大小增加到两倍时,如果我 select 另一个单元格的大小增加和减少,这是以前的selected 尺寸。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.states count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"SimpleTableCell";
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.stateName.text = [self.states objectAtIndex:indexPath.row];
return cell;
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40;
}
@end
如果您使用的是自动版式,则只需添加
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// for particular index
return UITableViewAutomaticDimension;
}
如果不使用自动布局则
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 1){
return 80;
}else{
return 44;
}
}
拿
一个 属性 selectedIndexPath
@property (strong, nonatomic) NSIndexPath * selectedIndexPath;
在
中设置
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
selectedIndexPath = indexPath;
[tableView reloadData];
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectedIndexPath != nil && indexPath == selectedIndexPath){
return 80;
}
return 40;
}
我需要设置我的 UITableView
单元格,当我 select 一个单元格的大小增加到两倍时,如果我 select 另一个单元格的大小增加和减少,这是以前的selected 尺寸。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.states count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"SimpleTableCell";
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.stateName.text = [self.states objectAtIndex:indexPath.row];
return cell;
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40;
}
@end
如果您使用的是自动版式,则只需添加
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// for particular index
return UITableViewAutomaticDimension;
}
如果不使用自动布局则
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 1){
return 80;
}else{
return 44;
}
}
拿
一个 属性 selectedIndexPath
@property (strong, nonatomic) NSIndexPath * selectedIndexPath;
在
中设置- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
selectedIndexPath = indexPath;
[tableView reloadData];
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectedIndexPath != nil && indexPath == selectedIndexPath){
return 80;
}
return 40;
}