私は目的UITableViewCell
の c Expanded に取り組んでいますが、正しく機能していません。私のコードは...
self.nameArr = [[NSMutableArray alloc]initWithObjects: @"Name1", @"Name2", @"Name3", @"Name4", @"Name5", @"Name6", @"Name7", @"Name8", @"Name9", @"Name10", nil];
self.phoneNoArray = [[NSMutableArray alloc]initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", nil];
self.emailDArray = [[NSMutableArray alloc]initWithObjects:@"EMail ID1", @"EMail ID2", @"EMail ID3", @"EMail ID4", @"EMail ID5", @"EMail ID6", @"EMail ID7", @"EMail ID8", @"EMail ID9", nil];
//#pragma mark - TableView methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.nameArr.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:section]])
{
return 2;
} else {
return 0;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ViewControllerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ViewControllerCell"];
if (cell ==nil)
{
[tblView registerClass:[ViewControllerCell class] forCellReuseIdentifier:@"ViewControllerCell"];
cell = [tblView dequeueReusableCellWithIdentifier:@"ViewControllerCell"];
}
for (int j=0; j<=self.i; j++) {
if (indexPath.row == 0) {
NSLog(@"Index path0 :%lu", indexPath.row);
cell.lblName.text = [self.phoneNoArray objectAtIndex:self.i];
} else {
NSLog(@"Index path1 :%lu", indexPath.row);
cell.lblName2.text = [self.emailDArray objectAtIndex:self.i];
}
}
cell.backgroundColor = [UIColor blueColor];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 44.0f;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
ViewControllerCellHeader *headerView = [tableView dequeueReusableCellWithIdentifier:@"ViewControllerCellHeader"];
if (headerView ==nil)
{
[tblView registerClass:[ViewControllerCellHeader class] forCellReuseIdentifier:@"ViewControllerCellHeader"];
headerView = [tableView dequeueReusableCellWithIdentifier:@"ViewControllerCellHeader"];
}
headerView.lbTitle.text = [self.nameArr objectAtIndex:section];
if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:section]])
{
headerView.btnShowHide.selected = YES;
}
//Assigning tags for buttons on tableView cells ...
headerView.btnShowHide.tag = section;
[[headerView btnShowHide] setTag:section];
[[headerView btnShowHide] addTarget:self action:@selector(btnTapShowHideSection:) forControlEvents:UIControlEventTouchUpInside];
//random color
[headerView.contentView setBackgroundColor:[UIColor clearColor]];
return headerView.contentView;
}
-(IBAction)btnTapShowHideSection:(UIButton*)sender
{
self.i = sender.tag;
if (!sender.selected)
{
[arrSelectedSectionIndex addObject:[NSNumber numberWithInteger:sender.tag]];
sender.selected = YES;
}else{
sender.selected = NO;
if ([arrSelectedSectionIndex containsObject:[NSNumber numberWithInteger:sender.tag]])
{
[arrSelectedSectionIndex removeObject:[NSNumber numberWithInteger:sender.tag]];
}
}
[tblView reloadSections:[NSIndexSet indexSetWithIndex:sender.tag] withRowAnimation:UITableViewRowAnimationAutomatic];
}
誰でも私に提案できますか...私はこのような出力を得ています..
これは私の出力画像です
このまま出したい