一、在Define目录里建立Const.h文件,用于保存一些经常使用的宏命令网络
#define CURRENT_APPID @"" #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) #define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0) #define IS_IOS8_AND_UP ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) #define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width) #define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height) #define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT)) #define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT)) #define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0) #define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0) #define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0) #define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0) // View 坐标(x,y)和宽高(width,height) #define X(v) (v).frame.origin.x #define Y(v) (v).frame.origin.y #define WIDTH(v) (v).frame.size.width #define HEIGHT(v) (v).frame.size.height //定义部分经常使用颜色 #define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A] //默认的文字大小 #define BASE_FONT_SIZE 15 #define BASE_TABLEVIEWCELL_HEIGHT 46 #define BASE_COLOR_MAIN COLOR(105,175,0,1) #define BASE_COLOR_TOPBAR COLOR(57,172,105,1) #define BASE_STATUSBAR_HEIGHT [[UIApplication sharedApplication] statusBarFrame].size.height
二、在Define目录里建立UrlDefine.h文件,用于保存一些网络请求的地址app
#define BASE_URL @"http://192.168.1.117:2002" #define BASE_URL_MAIN_RECOMMAND @"/house.ashx?action=recommand" #define BASE_URL_SALE @"/house.ashx?action=list&housetype=1" #define BASE_URL_RENT @"/house.ashx?action=list&housetype=2" #define BASE_URL_PROJECT @"/project.ashx"
三、在Define目录里建立PrefixMain.pch文件,用于包含一些预处理文件(默认不会启用pch,因此须要一些设置)工具
#define ISDEBUG //定义变量 #import "Const.h" #import "UrlDefine.h" //第三方组件 #import "AFNetworking.h" #import "UIView+Toast.h" #import "SVProgressHUD.h" #import "Bugly/CrashReporter.h" #import "UIImageView+WebCache.h" #import "MJRefresh.h" #import "IQKeyboardManager.h" //实用工具 #import "ToolsHelper.h" #import "HttpHelper.h" //正式环境不输出日志 #ifndef __OPTIMIZE__ #define NSLog(...) NSLog(__VA_ARGS__) #else #define NSLog(...) {} #endif
四、进入Targets,Build Settings,搜索Complie Prefix Header,修改成yes网站
五、而后在Prefix Header中增长pch的文件路径便可。须要在debug和release中都进行添加。ui
$(SRCROOT)/customerapp/PrefixMain.pchatom
解决两个问题,一个是TabBar的图标问题,二个是每一个页面不单单是个UIViewController,应该这个页面还能够跳转到下一个页面,因此这五个页面应该是UINavigationController。spa
修改AppDelegate.m里的代码以下。debug
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; //建立并初始化TabBarController self.tabBarController=[[UITabBarController alloc] init]; self.window.rootViewController = self.tabBarController; //建立五个视图控制器 RDMainViewController *VCMain = [[RDMainViewController alloc] init]; RDProjectListTableViewController *VCProjectList = [[RDProjectListTableViewController alloc] init]; RDSaleListTableViewController *VCSaleList = [[RDSaleListTableViewController alloc] init]; RDRentListTableViewController *VCRentList = [[RDRentListTableViewController alloc] init]; RDMyTableViewController *VCMy = [[RDMyTableViewController alloc] init]; //为视图控制器添加导航栏控制器 UINavigationController *navVCMain= [[UINavigationController alloc]initWithRootViewController:VCMain]; UINavigationController *navVCProjectList = [[UINavigationController alloc]initWithRootViewController:VCProjectList]; UINavigationController *navVCSaleList = [[UINavigationController alloc] initWithRootViewController:VCSaleList]; UINavigationController *navVCRentList = [[UINavigationController alloc] initWithRootViewController:VCRentList]; UINavigationController *navVCMy = [[UINavigationController alloc] initWithRootViewController:VCMy]; self.tabBarController.viewControllers=[NSArray arrayWithObjects:navVCMain, navVCProjectList, navVCSaleList,navVCRentList,navVCMy,nil]; //设置标题 navVCMain.tabBarItem.title=@"首页"; navVCProjectList.tabBarItem.title=@"新房"; navVCSaleList.tabBarItem.title=@"二手房"; navVCRentList.tabBarItem.title=@"租房"; navVCMy.tabBarItem.title=@"我"; //设置图标 navVCMain.tabBarItem.image = [UIImage imageNamed:@"icon_tab_house"]; navVCProjectList.tabBarItem.image = [UIImage imageNamed:@"icon_tab_building"]; navVCSaleList.tabBarItem.image = [UIImage imageNamed:@"icon_tab_building"]; navVCRentList.tabBarItem.image = [UIImage imageNamed:@"icon_tab_building"]; navVCMy.tabBarItem.image = [UIImage imageNamed:@"icon_tab_user"]; navVCMain.tabBarItem.selectedImage = [UIImage imageNamed:@"icon_tab_house_press"]; navVCProjectList.tabBarItem.selectedImage = [UIImage imageNamed:@"icon_tab_building_press"]; navVCSaleList.tabBarItem.selectedImage = [UIImage imageNamed:@"icon_tab_building_press"]; navVCRentList.tabBarItem.selectedImage = [UIImage imageNamed:@"icon_tab_building_press"]; navVCMy.tabBarItem.selectedImage = [UIImage imageNamed:@"icon_tab_user_press"]; //一些通用颜色设置 [[UITabBar appearance] setTintColor:BASE_COLOR_MAIN]; [[UINavigationBar appearance] setBarTintColor:BASE_COLOR_TOPBAR]; [[UINavigationBar appearance] setBarStyle:UIBarStyleBlack]; [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; [self.window makeKeyAndVisible]; return YES; }
看看模拟器效果,还不错不是。日志
系统必定要有日志功能!系统必定要有日志功能!系统必定要有日志功能!code
不要期望用户替你提交bug,忠诚点的用户崩溃以后再打开一次,普通用户就直接骂句垃圾,而后就卸载了。用C#的时候用Log4NET记录错误日志。iOS程序固然也要有。
一、进入腾讯Bugly建立你的程序,获取监视ID。
二、AppDelegate.m加入以下代码便可。
后面的ID是腾讯给你的监视ID,不是你的APPID哦。
三、模拟器运行一次程序,而后返回腾讯bugly网站,看,成功了。
一、AppDelegate.m文件中加入以下代码便可。
二、须要用到这个功能的h文件加入。
@property(nonatomic,strong) IQKeyboardReturnKeyHandler *returnKeyHandler;
三、须要用到这个功能的m文件的viewDidLoad方法加入以下代码
如下是引用其余文章的。
“设置returnKeyHandler,能够点击键盘上的next键,自动跳到下一个输入框。最后一个输入框点击done自动收起键盘。 运行后,能够看到输入框随着键盘的弹出自动上下浮动。点击背景,键盘收起。全自动了。 这个库默认支持UITextField、UITextView、UIWebView、UIScrollView、UITableView、UICollectionView 最后要注意一点,它能够自动计算多个textField之间的前后顺序,排列依据是看addSubView的前后顺序。”
It doesn't really matter. [NSMutableArray array] is a nice shortcut, but you have to remember to retain it, so the question really is a matter of [[NSMutableArray array] retain] versus [[NSMutableArray alloc] init]. I usually use the former. The real convenience comes in when you need to statically fill the array; you can do it all in one message. [[NSMutableArray arrayWithObjects:...] retain] is faster than [[NSMutableArray alloc] init] followed by numerous [NSMutableArray addObject:(id)] calls.