您的位置:首页 > 移动开发 > IOS开发

iOS周刊 第三期

2015-06-26 19:59 399 查看
一.如何设置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,自带的返回有没有了。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: