点击Cell进行多控制器跳转的简便写法
2015-12-18 17:02
323 查看
#import "CYMemberCenterController.h"
#import <UIButton+WebCache.h>
#import "EPUserProfileViewController.h"
@interface
CYMemberCenterController ()
@property(nonatomic,strong)NSMutableArray *menuArray;
@end
@implementation CYMemberCenterController
- (void)viewDidLoad {
[superviewDidLoad];
self.headView.titleLabel.text
= @"个人中心";
self.headView.leftBtn.hidden
= YES;
self.tableView.backgroundColor =rgb(242,242,
242);
self.menuArray = [[NSMutableArrayalloc]initWithCapacity:0];
NSArray *m1Array =@[@{@"name":@"我的会员信息",@"icon":@"ks_acc_lines",@"ctr":@"EPUserProfileViewController"},
@{@"name":@"我的邀请",@"icon":@"ks_acc_lines",@"ctr":@""}];
NSArray *m2Array =@[@{@"name":@"我的账户",@"icon":@"ks_acc_lines",@"ctr":@"CYMyAccountViewController"}];
NSArray *m3Array =@[@{@"name":@"消息",@"icon":@"ks_acc_lines",@"ctr":@"CYMessageListViewController"},
@{@"name":@"设置",@"icon":@"ks_acc_lines",@"ctr":@"MCSettingViewController"}];
[self.menuArrayaddObject:m1Array];//创建三个数组,里面装字典然后,在字典里面将数据封装起来。
[self.menuArrayaddObject:m2Array];
[self.menuArrayaddObject:m3Array];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return
self.menuArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section !=0) {
return10;
}
return0.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath{
return45;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *secArray = self.menuArray[section];
return secArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath{
staticNSString *Identifier =@"Cell";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:Identifier];
if (!cell) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:Identifier];
cell.backgroundColor = [UIColorwhiteColor];
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
}
NSArray *funcArray = self.menuArray[indexPath.section];
NSDictionary *menuDit = funcArray[indexPath.row];
cell.textLabel.text = menuDit[@"name"];
cell.textLabel.font = [UIFontsystemFontOfSize:14];
[cell.imageViewsetImage:[UIImageimageNamed:menuDit[@"icon"]]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath{
[tableView deselectRowAtIndexPath:indexPathanimated:YES];
NSArray *funcArray = self.menuArray[indexPath.section];
NSDictionary *menuDit = funcArray[indexPath.row];
UIViewController *ctr = (UIViewController*)[[NSClassFromString(menuDit[@"ctr"])alloc]init];
if ([ctrisKindOfClass:[EPUserProfileViewControllerclass]])//如果需要,可以将某个控制器单独提出来,进行传值
{
EPUserProfileViewController *memberCtr = (EPUserProfileViewController*)ctr;
memberCtr.profileEntryType =pUserInfoType;
}
ctr.hidesBottomBarWhenPushed =YES;
[self.navigationControllerpushViewController:ctranimated:YES];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#import <UIButton+WebCache.h>
#import "EPUserProfileViewController.h"
@interface
CYMemberCenterController ()
@property(nonatomic,strong)NSMutableArray *menuArray;
@end
@implementation CYMemberCenterController
- (void)viewDidLoad {
[superviewDidLoad];
self.headView.titleLabel.text
= @"个人中心";
self.headView.leftBtn.hidden
= YES;
self.tableView.backgroundColor =rgb(242,242,
242);
self.menuArray = [[NSMutableArrayalloc]initWithCapacity:0];
NSArray *m1Array =@[@{@"name":@"我的会员信息",@"icon":@"ks_acc_lines",@"ctr":@"EPUserProfileViewController"},
@{@"name":@"我的邀请",@"icon":@"ks_acc_lines",@"ctr":@""}];
NSArray *m2Array =@[@{@"name":@"我的账户",@"icon":@"ks_acc_lines",@"ctr":@"CYMyAccountViewController"}];
NSArray *m3Array =@[@{@"name":@"消息",@"icon":@"ks_acc_lines",@"ctr":@"CYMessageListViewController"},
@{@"name":@"设置",@"icon":@"ks_acc_lines",@"ctr":@"MCSettingViewController"}];
[self.menuArrayaddObject:m1Array];//创建三个数组,里面装字典然后,在字典里面将数据封装起来。
[self.menuArrayaddObject:m2Array];
[self.menuArrayaddObject:m3Array];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return
self.menuArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section !=0) {
return10;
}
return0.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath{
return45;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *secArray = self.menuArray[section];
return secArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath{
staticNSString *Identifier =@"Cell";
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:Identifier];
if (!cell) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:Identifier];
cell.backgroundColor = [UIColorwhiteColor];
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
}
NSArray *funcArray = self.menuArray[indexPath.section];
NSDictionary *menuDit = funcArray[indexPath.row];
cell.textLabel.text = menuDit[@"name"];
cell.textLabel.font = [UIFontsystemFontOfSize:14];
[cell.imageViewsetImage:[UIImageimageNamed:menuDit[@"icon"]]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath{
[tableView deselectRowAtIndexPath:indexPathanimated:YES];
NSArray *funcArray = self.menuArray[indexPath.section];
NSDictionary *menuDit = funcArray[indexPath.row];
UIViewController *ctr = (UIViewController*)[[NSClassFromString(menuDit[@"ctr"])alloc]init];
if ([ctrisKindOfClass:[EPUserProfileViewControllerclass]])//如果需要,可以将某个控制器单独提出来,进行传值
{
EPUserProfileViewController *memberCtr = (EPUserProfileViewController*)ctr;
memberCtr.profileEntryType =pUserInfoType;
}
ctr.hidesBottomBarWhenPushed =YES;
[self.navigationControllerpushViewController:ctranimated:YES];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- GUI - Web前端开发框架
- 评价ui设计作品好坏的八个标准(界面/交互设计研究)
- 为Yahoo! UI Extensions Grid增加内置的可编辑器
- Cocos2d-x UI开发之文本类使用实例
- 谈谈对jquery ui tabs 的理解
- 在IE 浏览器中使用 jquery的fadeIn() 效果 英文字符字体加粗
- UI Events 用户界面事件
- jquery UI Datepicker时间控件的使用方法(基础版)
- 基于jQuery UI CSS Framework开发Widget的经验
- jquery ui 1.7 ui.tabs 动态添加与关闭(按钮关闭+双击关闭)
- jQuery UI设置固定日期选择特效代码分享
- Jquery ajax 同步阻塞引起的UI线程阻塞问题
- jQuery UI的Dialog无法提交问题的解决方法
- jQuery ui实现动感的圆角渐变网站导航菜单效果代码
- jquery UI Datepicker时间控件的使用方法(终结版)
- jquery UI Datepicker时间控件的使用方法(加强版)
- 关于jQuery UI 使用心得及技巧
- jQuery ui 1.7更新小结
- 从零开始学习jQuery (十) jQueryUI常用功能实战
- jquery ui对话框实例代码