iOS周刊 第三期

一.如何设置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,自带的返回有没有了。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值