文档章节

qq

宝玉姚玉宝
 宝玉姚玉宝
发布于 2016/05/16 08:30
字数 1491
阅读 35
收藏 0
qq

AppDelegate.h AppDelegate.m

XiaoXiViewController.h XiaoXiViewController.m

HaoYouViewController.h HaoYouViewController.m

DongTaiViewController.h DongTaiViewController.m

TiaoViewController.h TiaoViewController.m TiaoViewController.xib

AppDelegate.h

#import <UIKit/UIKit.h> #import <CoreData/CoreData.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;

  • (void)saveContext;
  • (NSURL *)applicationDocumentsDirectory;

@end

AppDelegate.m

#import "AppDelegate.h" #import "XiaoXiViewController.h" #import "HaoYouViewController.h" #import "DongTaiViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch.

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; XiaoXiViewController *xiao = [[XiaoXiViewController alloc]init]; UINavigationController *Nav = [[UINavigationController alloc]initWithRootViewController:xiao]; UITabBarItem *item = [[UITabBarItem alloc]initWithTitle:@"消息" image:[UIImage imageNamed:@"tab_recent_press@2x"] selectedImage:[UIImage imageNamed:@"tab_recent_press@2x"]]; Nav.tabBarItem = item;

    HaoYouViewController *hao = [[HaoYouViewController alloc]init]; UINavigationController *Nav1 = [[UINavigationController alloc]initWithRootViewController:hao]; UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:@"好友" image:[UIImage imageNamed:@"tab_buddy_press@2x"] selectedImage:[UIImage imageNamed:@"tab_buddy_press@2x"]]; Nav1.tabBarItem = item1;

    DongTaiViewController *dong = [[DongTaiViewController alloc]init]; UINavigationController *Nav2 = [[UINavigationController alloc]initWithRootViewController:dong]; UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"动态" image:[UIImage imageNamed:@"tab_qworld_press@2x"] selectedImage:[UIImage imageNamed:@"tab_qworld_press@2x"]]; Nav2.tabBarItem = item2;

    UITabBarController *tab = [[UITabBarController alloc]init]; tab.viewControllers = @[Nav,Nav1,Nav2];

    self.window.rootViewController = tab;

    [self.window makeKeyAndVisible];

    return YES; }

  • (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. }

  • (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. }

  • (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. }

  • (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. }

  • (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. // Saves changes in the application's managed object context before the application terminates. [self saveContext]; }

#pragma mark - Core Data stack

@synthesize managedObjectContext = _managedObjectContext; @synthesize managedObjectModel = _managedObjectModel; @synthesize persistentStoreCoordinator = _persistentStoreCoordinator;

  • (NSURL *)applicationDocumentsDirectory { // The directory the application uses to store the Core Data store file. This code uses a directory named "---.QQ" in the application's documents directory. return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; }

  • (NSManagedObjectModel *)managedObjectModel { // The managed object model for the application. It is a fatal error for the application not to be able to find and load its model. if (_managedObjectModel != nil) { return _managedObjectModel; } NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"QQ" withExtension:@"momd"]; _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; return _managedObjectModel; }

  • (NSPersistentStoreCoordinator *)persistentStoreCoordinator { // The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. if (_persistentStoreCoordinator != nil) { return _persistentStoreCoordinator; }

    // Create the coordinator and store

    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"QQ.sqlite"]; NSError *error = nil; NSString *failureReason = @"There was an error creating or loading the application's saved data."; if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { // Report any error we got. NSMutableDictionary *dict = [NSMutableDictionary dictionary]; dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data"; dict[NSLocalizedFailureReasonErrorKey] = failureReason; dict[NSUnderlyingErrorKey] = error; error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict]; // Replace this with code to handle the error appropriately. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); }

    return _persistentStoreCoordinator; }

  • (NSManagedObjectContext *)managedObjectContext { // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) if (_managedObjectContext != nil) { return _managedObjectContext; }

    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (!coordinator) { return nil; } _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; [_managedObjectContext setPersistentStoreCoordinator:coordinator]; return _managedObjectContext; }

#pragma mark - Core Data Saving support

  • (void)saveContext { NSManagedObjectContext *managedObjectContext = self.managedObjectContext; if (managedObjectContext != nil) { NSError *error = nil; if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) { // Replace this implementation with code to handle the error appropriately. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } }

@end

XiaoXiViewController.h

#import <UIKit/UIKit.h>

@interface XiaoXiViewController : UIViewController

@end

XiaoXiViewController.m

#import "XiaoXiViewController.h" #import "TiaoViewController.h" @interface XiaoXiViewController ()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate,UISearchResultsUpdating,UISearchBarDelegate> { UITableView *_table; NSArray *imgArr; NSArray *perArr; NSArray *arr; NSArray *subArr; UISearchBar *search; UISearchDisplayController *_display;

}

@end

@implementation XiaoXiViewController

  • (void)viewDidLoad { [super viewDidLoad];

    self.title = @"消息"; self.view.backgroundColor = [UIColor whiteColor];

    arr = @[@"信息",@"对话"]; UISegmentedControl *segCtrl = [[UISegmentedControl alloc]initWithItems:arr];

    segCtrl.layer.cornerRadius=6; segCtrl.layer.masksToBounds=YES;

    [segCtrl addTarget:self action:@selector(clickSeg:) forControlEvents:UIControlEventValueChanged];

    segCtrl.selectedSegmentIndex=0; self.navigationItem.titleView=segCtrl;

    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom]; [btn1 setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];

    btn1.frame=CGRectMake(10, 10, 40, 40);

    btn1.layer.cornerRadius=20; btn1.layer.masksToBounds=YES;

    UIBarButtonItem *l=[[UIBarButtonItem alloc]initWithCustomView:btn1]; self.navigationItem.leftBarButtonItem=l;

    UIBarButtonItem *r=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(click1)]; // 添加右侧按钮 self.navigationItem.rightBarButtonItem=r; // 设置表格 _table=[[UITableView alloc]initWithFrame:CGRectMake(0,0,[UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStylePlain]; _table.delegate=self; _table.dataSource=self; _table.rowHeight=60;

    perArr=@[@"小阿布",@"大白",@"陌陌",@"皮卡丘",@"丘比特",@"张百万",@"张有才",@"科比"]; imgArr=@[@"1.jpg",@"1.jpg",@"1.jpg",@"1.jpg",@"1.jpg",@"1.jpg",@"1.jpg",@"1.jpg"];

    subArr=@[@"大好时光",@"晴空万里",@"大好时光",@"晴空万里",@"大好时光",@"晴空万里",@"大好时光",@"晴空万里"];

    [self.view addSubview:_table]; //搜索条 search=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)]; // 设置提示文字 search.placeholder=@"搜索"; // 设置 搜索框颜色 search.barTintColor=[UIColor colorWithRed:32.0/255 green:178.0/255 blue:170.0/255 alpha:0.25]; // 设置代理 search.delegate=self; // 初始化搜索控制器 _display=[[UISearchDisplayController alloc]initWithSearchBar:search contentsController:self];

    // 设置代理 _display.searchResultsDelegate=self; _display.searchResultsDataSource=self; // 给表格添加搜索 _table.tableHeaderView=search;

    }

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 8; }

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // 有复用池时 static NSString *cellId=@"cellId"; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellId]; if (!cell) { // UITableViewCellStyleSubtitle cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId]; } // 设置主标题 cell.textLabel.text=perArr[indexPath.row]; cell.textLabel.font=[UIFont systemFontOfSize:16]; cell.textLabel.textColor=[UIColor redColor]; // 设置副标题 cell.detailTextLabel.text=subArr[indexPath.row]; cell.detailTextLabel.font=[UIFont systemFontOfSize:12]; cell.detailTextLabel.textColor=[UIColor grayColor]; // 设置图片 cell.imageView.image=[UIImage imageNamed:[imgArr objectAtIndex:indexPath.row]]; // imageView的圆角 cell.imageView.layer.cornerRadius=30; cell.imageView.layer.masksToBounds=YES; // 时间按钮 UIButton *btntime=[UIButton buttonWithType:UIButtonTypeRoundedRect]; [btntime setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal]; btntime.frame=CGRectMake(200, 10, 100, 20); [btntime setTitle:@"05:20" forState:UIControlStateNormal]; btntime.alpha=0.6; cell.accessoryView=btntime;

    return cell; } -(void)click1 { UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"添加好友" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil]; alert.alertViewStyle=UIAlertViewStylePlainTextInput; [alert show];

}

//设置分段控件的方法 -(void)clickSeg:(UISegmentedControl *)ss { if (ss.selectedSegmentIndex==1) { // 隐藏 桌面 _table.hidden=YES;

    TiaoViewController *tiao = [[TiaoViewController alloc]init];
    [self.navigationController pushViewController:tiao animated:YES];
    
}else
{
    _table.hidden=NO;
}

} //点击单元格时触发的方法 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row==0) { // 跳转到下个界面 TiaoViewController *jump=[[TiaoViewController alloc]init]; [self.navigationController pushViewController:jump animated:YES];

}

}

  • (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }

/* #pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */

@end

HaoYouViewController.m

#import "HaoYouViewController.h"

@interface HaoYouViewController ()

@end

@implementation HaoYouViewController

  • (void)viewDidLoad { [super viewDidLoad]; self.title = @"好友"; self.view.backgroundColor = [UIColor blueColor];

}

  • (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }

/* #pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */

@end

DongTaiViewController.m

#import "DongTaiViewController.h"

@interface DongTaiViewController ()

@end

@implementation DongTaiViewController

  • (void)viewDidLoad { [super viewDidLoad]; self.title = @"动态"; self.view.backgroundColor = [UIColor yellowColor]; }

  • (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }

/* #pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */

@end

© 著作权归作者所有

共有 人打赏支持
上一篇: 图书查询
下一篇: shipingditu
宝玉姚玉宝
粉丝 1
博文 6
码字总数 9560
作品 0
东城
高级程序员
私信 提问

暂无文章

中国龙-扬科
4分钟前
0
0
假若明天来临——《AI.未来》读后感3900字

假若明天来临——《AI.未来》读后感3900字: 你有没有想过,如果有一天你被确诊为癌症患者,你会做些什么?你有没有想过,在你百年之后,你希望你的墓碑上刻写着什么内容? 在我翻开李开复老...

原创小博客
10分钟前
0
0
tomcat线程模型

Connector结构 BIO模式 NIO模式

grace_233
50分钟前
2
0
Javascript

变量定义 以$,_,字母开头 大小写敏感 var 关键字声明变量 声明未赋值undefined 数据类型 字符串,数字,布尔,数组,NULL,undefined 变量均为对象 函数 无默认值 var声明的是局部变量 函数外声明...

关元
51分钟前
1
0
文件系统、服务、防火墙、SELINUX——安全四大金刚

一提到安全,大家都会想到防火墙,和文件系统权限。而实际工作环境中,我们在Linux的安全配置,会涉及到四个级别。我们思考一个场景,你要在百度盘中存放一个文件,这个动作需要考虑下面四个...

Linux就该这么学
52分钟前
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部