点击Cell进行多控制器跳转的简便写法

本文介绍了一个iOS应用中个人中心页面的设计与实现过程,包括菜单结构组织、单元格配置及控制器跳转等关键技术细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值