tableView的懒懒的跳转方式,加载数据源方式
2015-11-18 18:06
465 查看
二者差不多,拿数据源说吧,n个section,每个section里面cell个数不固定,数据源内容不一定,导致cell形式会不一样
从数据源中取如果写if else,或者switch都不满意,也许Swift更牛一些,这里不提
说白了就是想根据所具有资源计算出不同cell对应的唯一的数据源数组的索引值
写的不好,如果有更好的希望分享一下,互相学习!(几十个scetion应该没有明显的效率诧异)
不多说上代码:
-(NSArray *)arrayTitle
{
if (!_arrayTitle) {
_arrayTitle = @[@"不让他(她)看我的家谱",@"不让他(她)看我的动态",@"不看他(她)的动态"];
}
return @[@"不让他(她)看我的家谱",@"不让他(她)看我的动态",@"不看他(她)的动态"];
}
-(NSArray *)arrayVCForJump
{
if (!_arrayVCForJump) {
_arrayVCForJump = @[[MHNotShowFamilyTreeController class],[MHNotShowEventToOtherController class],[MHNotSeeOtherEventController class]];
}
return _arrayVCForJump = @[[MHNotShowFamilyTreeController class],[MHNotShowEventToOtherController class],[MHNotSeeOtherEventController class]];
}
#pragma mark计算出当前数组的索引值,根据indexPath保证不会因为section多而重复
-(NSInteger)getCurrentIndexForDataArray:(NSIndexPath*)indexPath tableView:(UITableView *)tableView
{
//****************
self.numOfIndexPromate =0;
for (NSInteger i=0; i<indexPath.section; i++) {
self.numOfIndexPromate += [tableView numberOfRowsInSection:i];
}
//***************
return self.numOfIndexPromate;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//cell很少暂时可不考虑重用
MHPrivacyTableViewCell * cell = [[MHPrivacyTableViewCell alloc]init];
cell.textLabel.textColor = MHEventCellTitleColor;
// cell.textLabel.text = self.arrayTitle[indexPath.row+indexPath.section];//此处取值在多个section不唯一,以后要注意
NSInteger num = [self getCurrentIndexForDataArray:indexPath tableView:tableView];
cell.textLabel.text = self.arrayTitle[num+indexPath.row];
return cell;
}
#pragma mark - 点击cell跳转代理
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger num = [self getCurrentIndexForDataArray:indexPath tableView:tableView];
Class strVcName = self.arrayVCForJump[indexPath.row+num];
// Class strVcName = self.arrayVCForJump[indexPath.row+indexPath.section];
NSString * strClassName = NSStringFromClass(strVcName);
if ([strClassName isContainOneStr:@"Controller"]) {
UIViewController * vc = [[strVcName alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}
else
{
return;
}
}
从数据源中取如果写if else,或者switch都不满意,也许Swift更牛一些,这里不提
说白了就是想根据所具有资源计算出不同cell对应的唯一的数据源数组的索引值
写的不好,如果有更好的希望分享一下,互相学习!(几十个scetion应该没有明显的效率诧异)
不多说上代码:
-(NSArray *)arrayTitle
{
if (!_arrayTitle) {
_arrayTitle = @[@"不让他(她)看我的家谱",@"不让他(她)看我的动态",@"不看他(她)的动态"];
}
return @[@"不让他(她)看我的家谱",@"不让他(她)看我的动态",@"不看他(她)的动态"];
}
-(NSArray *)arrayVCForJump
{
if (!_arrayVCForJump) {
_arrayVCForJump = @[[MHNotShowFamilyTreeController class],[MHNotShowEventToOtherController class],[MHNotSeeOtherEventController class]];
}
return _arrayVCForJump = @[[MHNotShowFamilyTreeController class],[MHNotShowEventToOtherController class],[MHNotSeeOtherEventController class]];
}
#pragma mark计算出当前数组的索引值,根据indexPath保证不会因为section多而重复
-(NSInteger)getCurrentIndexForDataArray:(NSIndexPath*)indexPath tableView:(UITableView *)tableView
{
//****************
self.numOfIndexPromate =0;
for (NSInteger i=0; i<indexPath.section; i++) {
self.numOfIndexPromate += [tableView numberOfRowsInSection:i];
}
//***************
return self.numOfIndexPromate;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//cell很少暂时可不考虑重用
MHPrivacyTableViewCell * cell = [[MHPrivacyTableViewCell alloc]init];
cell.textLabel.textColor = MHEventCellTitleColor;
// cell.textLabel.text = self.arrayTitle[indexPath.row+indexPath.section];//此处取值在多个section不唯一,以后要注意
NSInteger num = [self getCurrentIndexForDataArray:indexPath tableView:tableView];
cell.textLabel.text = self.arrayTitle[num+indexPath.row];
return cell;
}
#pragma mark - 点击cell跳转代理
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger num = [self getCurrentIndexForDataArray:indexPath tableView:tableView];
Class strVcName = self.arrayVCForJump[indexPath.row+num];
// Class strVcName = self.arrayVCForJump[indexPath.row+indexPath.section];
NSString * strClassName = NSStringFromClass(strVcName);
if ([strClassName isContainOneStr:@"Controller"]) {
UIViewController * vc = [[strVcName alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}
else
{
return;
}
}
相关文章推荐
- Java面向对象编程学习
- 基于项目需求开发JMeter插件
- Python——while和for循环
- 高德地图开发【覆盖物显示——Marker的使用(一)】
- android 键盘与输入框问题
- 我的第一篇博客
- 阿里云服务器ubuntu安装java运行环境
- jQuery-1.9.1源码分析系列(十) 事件系统——事件绑定
- 色情图片识别
- 【工业4.0时代,怎样为孩子筹备未来的教育?】有感
- 17个提升iOS开发效率的必用工具
- 学习html5的WebSocket连接
- Implement strStr()
- Jquery Ajax处理,服务端三种页面aspx,ashx,asmx的比较
- Surrounded Regions
- Servlet与jsp的“一语惊醒梦中人”的区别
- Android系统下载DownloadManager
- 批量获取网页css背景图片
- Jitter Removal in Image and Sequence
- [OpenGL ES 07-1]光照原理