一.如何設(shè)置button title 的位置
btn.textLabel.textAlignment = UITextAlignmentLeft是沒有作用的,我們需要設(shè)置
btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;
但是問題又出來逢净,此時(shí)文字會(huì)緊貼到做邊框慷蠕,我們可以設(shè)置
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
二.表格分組折疊
1.數(shù)據(jù)源
- (void)initData {
_mArrayData = [[NSMutableArray alloc]init];
for (int i = 'A'; i <= 'Z'; i++) {
NSMutableDictionary *smallGroupDict = [[NSMutableDictionary alloc]init];? //聲明小數(shù)組的字典
[smallGroupDict setObject:[NSString stringWithFormat:@"%c組",i] forKey:GROUP_NAME];
[smallGroupDict setObject:[NSNumber numberWithBool:YES] forKey:GROUP_STATE]; //該組的狀態(tài)是收起的
NSMutableArray *subArray = [[NSMutableArray alloc]init];
for (int j = 0; j < 5; j++) {
NSString *str = [NSString stringWithFormat:@"%c%d",i,j];
[subArray addObject:str];
}
[smallGroupDict setObject:subArray forKey:GROUP_CONTENT];
[_mArrayData addObject:smallGroupDict];
}
}
2.設(shè)置sectionView
3.點(diǎn)擊事件
- (void)buttonClick:(UIButton *)btn {
NSMutableDictionary *dict = [_mArrayData objectAtIndex:btn.tag-100];
NSNumber *number = [dict objectForKey:GROUP_STATE];
if ([number boolValue]) {
[dict setObject:[NSNumber numberWithBool:NO] forKey:GROUP_STATE];
}
else {
[dict setObject:[NSNumber numberWithBool:YES] forKey:GROUP_STATE];
}
[_tabelView reloadSections:[NSIndexSet indexSetWithIndex:btn.tag-100] withRowAnimation:UITableViewRowAnimationTop];
}
4.代理方法
#pragma mark - 獲取數(shù)據(jù)視圖的組數(shù),選擇性實(shí)現(xiàn)驻呐,可以實(shí)現(xiàn)也可以不實(shí)現(xiàn),默認(rèn)的返回值為1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return _mArrayData.count;
}
#pragma mark - 獲取每一組的行數(shù)璃弄,必須實(shí)現(xiàn)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSMutableDictionary *smallDict = [_mArrayData objectAtIndex:section];
//section 獲得當(dāng)前組數(shù)
NSNumber *number = [smallDict objectForKey:GROUP_STATE];
if ([number boolValue]) {
NSArray *array = [smallDict objectForKey:GROUP_CONTENT];
return array.count; //返回當(dāng)前組數(shù)的行數(shù) ;
}
return 0; //返回當(dāng)前組數(shù)的行數(shù)
}
#pragma mark - 獲取單元格對象肝断,必須實(shí)現(xiàn)的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //indexPath 代表的是獲得的當(dāng)前組數(shù)的第幾行
NSString *str = @"ID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str]; //獲取可以重復(fù)利用的單元格
if (cell == nil) {? //沒有獲得可以重復(fù)利用的單元格
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str] autorelease];
}
NSDictionary *smallGroupDict = [_mArrayData objectAtIndex:indexPath.section]; //獲取當(dāng)前對應(yīng)的小組對象
NSArray *smallGroup = [smallGroupDict objectForKey:GROUP_CONTENT];
NSString *strValue = [smallGroup objectAtIndex:indexPath.row];? //獲取對應(yīng)行的數(shù)據(jù)
cell.textLabel.text = strValue;? //單元格文字賦值
return cell;
}
三迂尝,push 動(dòng)畫
項(xiàng)目要做一個(gè)頁面翻轉(zhuǎn)的效果
之前用的是模態(tài)化的方法 UIModalTransitionStyleFlipHorizontal
但是不能用push鞠评,自帶的返回有沒有了茂蚓。