一.如何設置button title 的位置
btn.textLabel.textAlignment = UITextAlignmentLeft是沒有作用的,我們需要設置
btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;
但是問題又出來,此時文字會緊貼到做邊框,我們可以設置
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
二.表格分組折疊
1.數據源
- (void)initData {
_mArrayData = [[NSMutableArray alloc]init];
for (int i = 'A'; i <= 'Z'; i++) {
NSMutableDictionary *smallGroupDict = [[NSMutableDictionary alloc]init];? //聲明小數組的字典
[smallGroupDict setObject:[NSString stringWithFormat:@"%c組",i] forKey:GROUP_NAME];
[smallGroupDict setObject:[NSNumber numberWithBool:YES] forKey:GROUP_STATE]; //該組的狀態是收起的
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.設置sectionView
3.點擊事件
- (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 - 獲取數據視圖的組數,選擇性實現,可以實現也可以不實現,默認的返回值為1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return _mArrayData.count;
}
#pragma mark - 獲取每一組的行數,必須實現
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSMutableDictionary *smallDict = [_mArrayData objectAtIndex:section];
//section 獲得當前組數
NSNumber *number = [smallDict objectForKey:GROUP_STATE];
if ([number boolValue]) {
NSArray *array = [smallDict objectForKey:GROUP_CONTENT];
return array.count; //返回當前組數的行數 ;
}
return 0; //返回當前組數的行數
}
#pragma mark - 獲取單元格對象,必須實現的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //indexPath 代表的是獲得的當前組數的第幾行
NSString *str = @"ID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str]; //獲取可以重復利用的單元格
if (cell == nil) {? //沒有獲得可以重復利用的單元格
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str] autorelease];
}
NSDictionary *smallGroupDict = [_mArrayData objectAtIndex:indexPath.section]; //獲取當前對應的小組對象
NSArray *smallGroup = [smallGroupDict objectForKey:GROUP_CONTENT];
NSString *strValue = [smallGroup objectAtIndex:indexPath.row];? //獲取對應行的數據
cell.textLabel.text = strValue;? //單元格文字賦值
return cell;
}
三,push 動畫
項目要做一個頁面翻轉的效果
之前用的是模態化的方法 UIModalTransitionStyleFlipHorizontal
但是不能用push,自帶的返回有沒有了。