qq
qq
宝玉姚玉宝 发表于2年前
qq
  • 发表于 2年前
  • 阅读 33
  • 收藏 0
  • 点赞 2
  • 评论 0

【腾讯云】买域名送云解析+SSL证书+建站!>>>   

摘要: 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

标签: qq
  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 1
博文 6
码字总数 9560
×
宝玉姚玉宝
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: