iOS分組通訊錄效果+側滑菜單(MMDrawerController)

來源:互聯網
上載者:User

標籤:class   .com   post   首頁   uiview   split   通訊   string   data-   

前言的廢話…能夠忽略
自從學會了使用Cocoapod,就欲罷不能了!由於太簡單太贊了,不用再把原始碼粘到project裡了!
參見戴維營部落格中的解說:Cocoapod 安裝以及使用
先上一下,請原諒我手殘錄的效果不是非常理想,大致就是這個意思

接下來上代碼!

1.通訊錄

通訊錄基本的就是建立索引欄和section的關聯,其次是初始化索引欄資料和每一個section的title.關於索引欄資料,假設寫介面的小哥人好的話就會直接幫你返回ABCD…假設非常不幸,介面小哥不給你返回索引欄資料,那就得自己處理了!(處理方法興許再補上,如今先假設接收到了索引欄資料)

(1.)私人成員

 @property(nonatomic,strong)NSArray* bottomTableData; @property(nonatomic,strong)NSArray* indexData;

(2.)相關函數

    //每一個section 的title- (UIView *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{    return [_indexData objectAtIndex:section];}//返回索引欄資料- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{    return _indexData;}//建立索引欄和section的關聯     - (NSInteger)tableView:(UITableView *)tableView             sectionForSectionIndexTitle:(NSString *)title                    atIndex:(NSInteger)index{  NSInteger section = [_indexData indexOfObject:title];  return section;}
2.側滑菜單

(1.)私人成員

@property (weak, nonatomic) IBOutlet UITableView *topTableView;//新的好友,我的粉絲,我的群@property (nonatomic,strong)BottomTableView* bottomTabelView;//下半部分的通訊錄@property(nonatomic,strong)UILabel* groupNameLbl;@property(nonatomic,strong)NSArray* topTableData;@property(nonatomic,strong)NSArray* bottomTableData;@property(nonatomic,strong)NSArray* indexData;//索引資料,對接介面後依據返回的對應資料進行修改@property(nonatomic,strong)NSArray* leftMenuData;//側滑菜單 

(2.)相關函數

    1>.在viewDidLoad中初始化資料    2>.設定側滑菜單(使用MMDrawerController)!LeftSideDrawerViewController* leftMenuController = [[LeftSideDrawerViewController alloc] init];leftMenuController.imgData = @[@"allFriend",@"jiaren",@"pengyou",@"tongxue",@"weifenzu"];/**注意:每一個頁面要用NavigationViewController包一下.我不是在首頁面寫的側滑菜單,而是在模態表單裡寫的.這裡的參數須要細緻檢查,非常easy出現錯誤,假設參數出現錯誤,介面效果會有問題的,詳細的你能夠自己試著修改一下,深刻的理解一下.我這裡的self不過一個ViewController,所以須要NavigationViewController再包一層.*/self.drawController = [[MMDrawerController alloc] initWithCenterViewController:[[NavigationViewController alloc] initWithRootViewController:self] leftDrawerViewController:leftController];[_drawController setShowsShadow:NO];[_drawController setMaximumLeftDrawerWidth:kScreenWidth*4/5];[_drawController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];[_drawController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];UIColor * tintColor = [UIColor colorWithRed:29.0/255.0                                      green:173.0/255.0                                       blue:234.0/255.0                                      alpha:1.0];[_window setTintColor:tintColor];_window.rootViewController = _drawController;[_window makeKeyAndVisible];3>.初始化資料_topTableData = @[@[@"新的朋友(0)",@"qunmemberaction"],@[@"我的粉絲(0)",@"qunweiboaction"],@[@"我的群(0)",@"qunmemberaction"]];    _bottomTableData = @[@[@"啊1",@"啊2"],@[@"波波",@"菠菜"],@[@"赫赫"],@[@"校內外助手",@"新人",@"小人",@"昕人"]];_indexData = @[@"A",@"B",@"H",@"X"];_leftMenuData = @[@"所有好友(2)",@"家人(0)",@"朋友(0)",@"同學(0)",@"未分組(2)"];4>.選擇左側菜單中某一項,側滑菜單關閉並重新整理首頁面的資料a.側滑菜單.m中- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    ContactsViewController* contactController = [[ContactsViewController alloc] initWithNibName:@"ContactsViewController" bundle:nil];    self.leftDelegate = contactController;    [self.leftDelegate  passToContacts:[NSString  stringWithFormat:@"%ld",(long)indexPath.row]];    [self.mm_drawerController closeDrawerAnimated:YES completion:nil];}b.首頁面.m中- (void)passToContacts:(NSString*)value{ //又一次請求好友通訊錄,並重新整理tableview  groupIndex = [value intValue];  [self viewDidLoad];}
3.從首頁面返回上一級頁面
//更改window的根視圖控制器- (void)pressCancleBtn:(id)sender{    TabbarViewController* tabbarController =  [[TabbarViewController alloc]init];    tabbarController.selectedIndex = 4;self.window.rootViewController = tabbarController;    [self.window makeKeyAndVisible];}
最後的囉嗦

由於是菜鳥,所以希望大家多多提意見,共同進步!最後附代碼地址:MollyMmm的github

iOS分組通訊錄效果+側滑菜單(MMDrawerController)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.