閑著無(wú)聊.瞎寫(xiě).目前貌似有點(diǎn)簡(jiǎn)單了...畢竟剛?cè)腴T時(shí)困擾了好久...
#import "CeShiTableViewController.h"
@interface CeShiTableViewController ()
@property (nonatomic , strong) NSArray * titleAry;
@property (nonatomic , strong) NSArray *contentAry;
@property (nonatomic , strong) NSMutableArray *SelectAry;
@end
@implementation CeShiTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
self.titleAry = @[@"組1",@"組2",@"組3"];
self.contentAry = @[@[@"123",@"1234",@"111",@"666",@"dsadasd",@"dasfsa",@"2年前第一次寫(xiě)覺(jué)得好難",@"2年后再寫(xiě)實(shí)在有點(diǎn)簡(jiǎn)單了"],@[@"2",@"222",@"2222222",@"21"],@[@"UI股",@"濕噠噠",@"多撒大所",@"大神的撒范德薩范德薩范德薩發(fā)",@"sfdsf",@"wfwfwef",@"fs"]];
self.SelectAry = [@[@(0),@(0),@(0)]mutableCopy];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
self.tableView.backgroundColor = [UIColor redColor];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
return _titleAry.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
if ([self.SelectAry[section] isEqualToNumber:@(0)]) {//沒(méi)點(diǎn)擊
return 0;
}else
return ((NSArray * )self.contentAry[section]).count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.textLabel.text = self.contentAry[indexPath.section][indexPath.row];
cell.backgroundColor = [UIColor yellowColor];
// Configure the cell...
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 30;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIButton *headerBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
[headerBtn setTitle:self.titleAry[section] forState:UIControlStateNormal];
headerBtn.tag = 1000 + section;
[headerBtn addTarget:self action:@selector(ChangeNum:) forControlEvents:UIControlEventTouchUpInside];
headerBtn.backgroundColor = [UIColor blackColor];
return headerBtn;
}
- (void)ChangeNum:(UIButton *)sender{
int i = (int)sender.tag - 1000;
if ([self.SelectAry[i] isEqualToNumber:@(0)]) {//沒(méi)展開(kāi)
[self.SelectAry replaceObjectAtIndex:i withObject:@(1)];//去展開(kāi)
}else//展開(kāi)了
{
[self.SelectAry replaceObjectAtIndex:i withObject:@(0)];
}
//刷新tableview(區(qū))
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:i] withRowAnimation: UITableViewRowAnimationFade];
NSLog(@"點(diǎn)擊數(shù)組%@",self.SelectAry);
}