IOS -- Address Book (UITableViewController), uitableview address book

Source: Internet
Author: User
Tags allkeys

IOS -- Address Book (UITableViewController), uitableview address book

This article mainly implements some functions of the address book (group name, index, group name) and so on:

If you don't talk much about it, go first:

 

You need to import a plist file in the project. The file diagram is as follows:

Project directory file:

 

 

Engineering procedures:

RootTableViewController. h

 

#import <UIKit/UIKit.h>@interface RootTableViewController : UITableViewController@property(strong,nonatomic) NSDictionary *dic;@property(strong,nonatomic) NSArray *arrkeys;@end

 

 

RootTableViewController. m

# Import "RootTableViewController. h "@ interface RootTableViewController () @ end @ implementation RootTableViewController-(void) viewDidLoad {[super viewDidLoad]; NSString * path = [[NSBundle mainBundle] pathForResource: @" sortednames "ofType: @ "plist"]; self. dic = [NSDictionary dictionaryWithContentsOfFile: path]; // NSLog (@ "% @", self. dic); // NSLog (@ "% @", self. dic. allKeys); // the output of the dictionary sorting dictionary is unordered and must be sorted by self. arrkeys = [self. dic. allKeys sortedArrayUsingSelector: @ selector (compare :)]; // NSLog (@ "% @", self. arrkeys); // Unique Identifier [self. tableView registerClass: [UITableViewCell class] forCellReuseIdentifier: @ "reuseIdentifier"];}-(void) Detail {[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated .} # pragma mark-number of each Group-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {return self. arrkeys. count ;}# pragma mark-number of groups-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {NSString * key = self. arrkeys [section]; NSArray * tempArr = self. dic [key]; // NSLog (@ "% @", key); return tempArr. count;}-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {UITableViewCell * cell = [tableView metadata: @ "reuseIdentifier" forIndexPath: indexPath]; NSString * key = self. arrkeys [indexPath. section]; NSArray * tempArr = self. dic [key]; NSString * name = tempArr [indexPath. row]; cell. textLabel. text = name; return cell;} # pragma mark-Method for returning the Row Height-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {return 50 ;} # pragma mark-system default start keyword-(NSString *) tableView :( UITableView *) tableView titleForHeaderInSection :( NSInteger) section {return self. arrkeys [section]; // return [NSString stringWithFormat: @ "% c", (char) ('A' + section)];} # pragma mark-Prefix keyword of Custom Auto size-(UIView *) tableView :( UITableView *) tableView viewForHeaderInSection :( NSInteger) section {UILabel * lbl = [[UILabel alloc] init]; lbl. backgroundColor = [UIColor redColor]; lbl. tintColor = [UIColor yellowColor]; lbl. text = self. arrkeys [section]; lbl. font = [UIFont systemFontOfSize: 30.0]; return lbl ;}# pragma mark-set the right index height-(CGFloat) tableView :( UITableView *) tableView heightForHeaderInSection :( NSInteger) section {return 50 ;}# pragma mark-set the list of titles of all partitions-(NSArray <NSString *> *) sectionIndexTitlesForTableView :( UITableView *) tableView {return self. arrkeys ;}# pragma mark-radio control format-(UITableViewCellAccessoryType) tableView :( UITableView *) tableView accessoryTypeForRowWithIndexPath :( NSIndexPath *) indexPath {if (indexPath. row = 0) {return UITableViewCellAccessoryCheckmark;} else if (indexPath. row = 1) {return UITableViewCellAccessoryDetailDisclosureButton;} else if (indexPath. row = 2) {return UITableViewCellAccessoryDisclosureIndicator;} else {return UITableViewCellAccessoryNone ;}}......... @ end

 

Note:

Various attributes and display specifications in the address book are set in RootTableViewController. m !!!

 

AppDelegate. h

#import <UIKit/UIKit.h>#import "RootTableViewController.h"@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@end

 

AppDelegate. m

#import "AppDelegate.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    self.window.rootViewController=[[UINavigationController alloc] initWithRootViewController:[[RootTableViewController alloc] initWithStyle:UITableViewStyleGrouped]];        return YES;}.......@end

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.