私はiPhoneアプリケーションで作業しており、UITableViewを使用してアプリケーションを開発しています。ユーザーがセクション1のUIButtonを押してB1メソッドを呼び出し、このテーブルビューにもう1つのセクションと行を追加すると、3つのセクションがあり、各セクションには1つの行があります。その正常に動作します。
アニメーションを追加しようとしました (セクションと行をもう 1 つ追加するため)。
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
しかし、すべての行とセクションをアニメーション化しますが、セクションと行を追加するときにアニメーションを追加したいです。これを処理する方法を教えてください。
前もって感謝します
私はこれを試しました:
- (void)viewDidLoad
{
[super viewDidLoad];
ExpandActive = NO;
self.title=@"Expand Tables";
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if(ExpandActive == YES)
{
return 4;
}
else
{
return 3;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 1;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if(ExpandActive == YES)
{
if(section == 0)
{
return @"Header1";
}
else if(section == 1)
{
return @"Header1";
}
else if(section == 2)
{
return @"Header1";
}
else if(section == 3)
{
return @"Header1";
}
}
else
{
if(section == 0)
{
return @"Header1";
}
else if(section == 1)
{
return @"Header1";
}
else if(section == 2)
{
return @"Header1";
}
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.userInteractionEnabled=YES;
if(ExpandActive == YES)
{
if(indexPath.section == 0)
{
UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
bg.backgroundColor = [UIColor clearColor];
bg.userInteractionEnabled = YES;
UIButton *btn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"Yes" forState:UIControlStateNormal];
btn.frame = CGRectMake(10, 5, 120, 40);
[btn addTarget:self action:@selector(B1) forControlEvents:UIControlEventTouchUpInside];
[bg addSubview:btn];
UIButton *btn1 =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn1 setTitle:@"No" forState:UIControlStateNormal];
btn1.frame = CGRectMake(180, 5, 120, 40);
[btn1 addTarget:self action:@selector(B2) forControlEvents:UIControlEventTouchUpInside];
[bg addSubview:btn1];
cell.backgroundView = bg;
[cell.contentView addSubview:bg];
}
else if(indexPath.section == 1)
{
text = [[UITextView alloc]initWithFrame:CGRectMake(0,0, 320, 50)];
text.text=@"sdadd";
[cell.contentView addSubview:text];
}
else if(indexPath.section == 2)
{
UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
bg.backgroundColor = [UIColor clearColor];
bg.userInteractionEnabled = YES;
UIButton *btn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"Yes" forState:UIControlStateNormal];
btn.frame = CGRectMake(10, 5, 120, 40);
[btn addTarget:self action:@selector(B5) forControlEvents:UIControlEventTouchUpInside];
[bg addSubview:btn];
UIButton *btn1 =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn1 setTitle:@"No" forState:UIControlStateNormal];
btn1.frame = CGRectMake(180, 5, 120, 40);
[btn1 addTarget:self action:@selector(B6) forControlEvents:UIControlEventTouchUpInside];
[bg addSubview:btn1];
cell.backgroundView = bg;
[cell.contentView addSubview:bg];
}
else if(indexPath.section == 3)
{
UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
bg.backgroundColor = [UIColor clearColor];
bg.userInteractionEnabled = YES;
UIButton *btn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"Yes" forState:UIControlStateNormal];
btn.frame = CGRectMake(10, 5, 120, 40);
[btn addTarget:self action:@selector(B5) forControlEvents:UIControlEventTouchUpInside];
[bg addSubview:btn];
UIButton *btn1 =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn1 setTitle:@"No" forState:UIControlStateNormal];
btn1.frame = CGRectMake(180, 5, 120, 40);
[btn1 addTarget:self action:@selector(B6) forControlEvents:UIControlEventTouchUpInside];
[bg addSubview:btn1];
cell.backgroundView = bg;
[cell.contentView addSubview:bg];
}
}
else
{
if(indexPath.section == 0)
{
UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
bg.backgroundColor = [UIColor clearColor];
bg.userInteractionEnabled = YES;
UIButton *btn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"Yes" forState:UIControlStateNormal];
btn.frame = CGRectMake(10, 5, 120, 40);
[btn addTarget:self action:@selector(B1) forControlEvents:UIControlEventTouchUpInside];
[bg addSubview:btn];
UIButton *btn1 =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn1 setTitle:@"No" forState:UIControlStateNormal];
btn1.frame = CGRectMake(180, 5, 120, 40);
[btn1 addTarget:self action:@selector(B2) forControlEvents:UIControlEventTouchUpInside];
[bg addSubview:btn1];
cell.backgroundView = bg;
[cell.contentView addSubview:bg];
}
else if(indexPath.section == 1)
{
UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
bg.backgroundColor = [UIColor clearColor];
bg.userInteractionEnabled = YES;
UIButton *btn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"Yes" forState:UIControlStateNormal];
btn.frame = CGRectMake(10, 5, 120, 40);
[btn addTarget:self action:@selector(B3) forControlEvents:UIControlEventTouchUpInside];
[bg addSubview:btn];
UIButton *btn1 =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn1 setTitle:@"No" forState:UIControlStateNormal];
btn1.frame = CGRectMake(180, 5, 120, 40);
[btn1 addTarget:self action:@selector(B4) forControlEvents:UIControlEventTouchUpInside];
[bg addSubview:btn1];
cell.backgroundView = bg;
[cell.contentView addSubview:bg];
}
else if(indexPath.section == 2)
{
UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
bg.backgroundColor = [UIColor clearColor];
bg.userInteractionEnabled = YES;
UIButton *btn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"Yes" forState:UIControlStateNormal];
btn.frame = CGRectMake(10, 5, 120, 40);
[btn addTarget:self action:@selector(B5) forControlEvents:UIControlEventTouchUpInside];
[bg addSubview:btn];
UIButton *btn1 =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn1 setTitle:@"No" forState:UIControlStateNormal];
btn1.frame = CGRectMake(180, 5, 120, 40);
[btn1 addTarget:self action:@selector(B6) forControlEvents:UIControlEventTouchUpInside];
[bg addSubview:btn1];
cell.backgroundView = bg;
[cell.contentView addSubview:bg];
}
}
return cell;
}
-(void)B1
{
NSLog(@"B1");
ExpandActive = YES;
[text removeFromSuperview];
[self.tableView reloadData];
}
-(void)B2
{
NSLog(@"B2");
ExpandActive = NO;
[self.tableView reloadData];
[text removeFromSuperview];
}