文档章节

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

© 著作权归作者所有

共有 人打赏支持
宝玉姚玉宝
粉丝 1
博文 6
码字总数 9560
作品 0
东城
高级程序员

暂无文章

Shell编程(expect同步文件、指定host和同步文件、构建文件分发系统、批量执行命令)

expect脚本同步文件 需求:自动同步文件 实验准备: A机器:192.168.248.130 B机器:192.168.248.129 实现: 1.A机器编写4.expect脚本文件,内容如下所示: #!/usr/bin/expectset passwd "...

蛋黄_Yolks
31分钟前
2
0
ppwjs之bootstrap颜色:背景颜色

<!DOCTYPT html><html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>ppwjs欢迎您</title><link rel="icon" href="/favicon.ico" ......

ppwjs
32分钟前
1
0
Ubuntu与 Fedora之对比

大家好。今天我将重点介绍两个流行的Linux发行版之间的一些特性和差异; Ubuntu 18.04和Fedora 28。它们都有自己的包管理; Ubuntu使用DEB,而Fedora使用RPM,但它们都具有相同的桌面环境(GNO...

linuxprobe16
36分钟前
2
0
线性代数入门

线性代数的概念对于理解机器学习背后的原理非常重要,尤其是在深度学习领域中。它可以帮助我们更好地理解算法内部到底是怎么运行的,借此,我们就能够更好的做出决策。所以,如果你真的希望了...

牛奋Debug
昨天
3
0
开发5分钟,调试2小时 - 该如何debug?

几年来我在答疑群、论坛、公众号、知乎回答的各种问题,没有一万也有八千。其中有三分之二以上都是在帮人看报错,帮人 debug(调试代码)。 可以说,会不会 debug,有没有 debug 的意识,懂不...

crossin
昨天
4
1

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部