iOS 使用UItableview实现宫格现实-以九宫格为例子
2013-03-28 11:14
363 查看
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath
{
return 44;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([m_showArray
count]%4)
{
return [m_showArray
count]/4+1;
}
else
{
return [m_showArray
count]/4;
}
}
-(void)selectBtItem:(id)sender
{
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static NSString *strIndicator =
@"CellId";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:strIndicator];
for (UIView *view
in cell.subviews)
{
if ([view isKindOfClass:[CustomButton
class]])
{
[view
removeFromSuperview];
}
}
if (!cell)
{
cell = [[[UITableViewCell
alloc]initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:strIndicator]autorelease];
cell.selectedBackgroundView = [[[UIView
alloc]
initWithFrame:cell.frame]
autorelease];
cell.selectedBackgroundView.backgroundColor = [UIColor
clearColor];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
for (int i =
0;i < 4; ++i)
{
if (([m_showArray
count]%4)&&(indexPath.row == [m_showArray
count]/4)&&([m_showArray
count]%4 == i))
{//不能被4整除的余数处理,
break;
}
CustomButton* tempBt = [[CustomButton
alloc] initWithFrame:CGRectMake(10+i*80,
10, 60,
20)];
tempBt.tag =
2000+i;
tempBt.m_tag =
m_index;
[tempBt setTitle:tempCity.cityName
forState:UIControlStateNormal];
[tempBt setTitleColor:[UIColor
whiteColor] forState:UIControlStateNormal];
tempBt.backgroundColor = [UIColor
clearColor];
[tempBt addTarget:self
action:@selector(selectBtItem:)
forControlEvents:UIControlEventTouchUpInside];
[cell
addSubview:tempBt];
[tempBt
release];
m_index = (m_index +
1)%[m_showArray
count];
}
return cell;
}
*)indexPath
{
return 44;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([m_showArray
count]%4)
{
return [m_showArray
count]/4+1;
}
else
{
return [m_showArray
count]/4;
}
}
-(void)selectBtItem:(id)sender
{
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static NSString *strIndicator =
@"CellId";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:strIndicator];
for (UIView *view
in cell.subviews)
{
if ([view isKindOfClass:[CustomButton
class]])
{
[view
removeFromSuperview];
}
}
if (!cell)
{
cell = [[[UITableViewCell
alloc]initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:strIndicator]autorelease];
cell.selectedBackgroundView = [[[UIView
alloc]
initWithFrame:cell.frame]
autorelease];
cell.selectedBackgroundView.backgroundColor = [UIColor
clearColor];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
for (int i =
0;i < 4; ++i)
{
if (([m_showArray
count]%4)&&(indexPath.row == [m_showArray
count]/4)&&([m_showArray
count]%4 == i))
{//不能被4整除的余数处理,
break;
}
CustomButton* tempBt = [[CustomButton
alloc] initWithFrame:CGRectMake(10+i*80,
10, 60,
20)];
tempBt.tag =
2000+i;
tempBt.m_tag =
m_index;
[tempBt setTitle:tempCity.cityName
forState:UIControlStateNormal];
[tempBt setTitleColor:[UIColor
whiteColor] forState:UIControlStateNormal];
tempBt.backgroundColor = [UIColor
clearColor];
[tempBt addTarget:self
action:@selector(selectBtItem:)
forControlEvents:UIControlEventTouchUpInside];
[cell
addSubview:tempBt];
[tempBt
release];
m_index = (m_index +
1)%[m_showArray
count];
}
return cell;
}
相关文章推荐
- iOS开发之UitableViewCell中UISwitch的使用,代理实现
- 【iOS】使用UITableView实现树视图
- 李洪强iOS开发之 - 实现九宫格并使用SDWebImage下载图片
- iOS 6 新特新CollectionView的使用实现九宫格
- ios 使用Starscream实现websocket简单例子
- iOS使用UITableView实现的富文本编辑器
- IOS使用UItableView实现下拉菜单组件(UITableView的使用方法)
- IOS控件系列----使用UITableView实现网格布局,自定义显示列数
- iOS 6 新特新CollectionView的使用实现九宫格
- iOS使用UITableView实现的富文本编辑器
- IOS 开发使用UITableView实现自动布局多个button 按钮
- iOS使用http post多图片上传带描述+java后台服务器,简单实现例子.
- [无限互联]IOS之MMdrawer框架的使用及实现原理
- iOS使用[核心动画]和[定时器]两种方式实现【呼吸灯动画】(仿蘑菇街价格标签)
- 在python中实现生产者和消费者的例子(一):使用multiprocessing和pipe()
- iOS使用UIScrollView实现无限循环轮播图
- iOS使用NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)
- ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局
- ios – 使用UINib加载xib文件实现UITableViewCell
- IOS - 使用NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)