您的位置:首页 > 其它

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;

}

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