前言
最近忙完項目比較閑露懒,想寫一篇博客來分享一些自學(xué)iOS的心得體會闯冷,希望對迷茫的你有所幫助。博主非科班出身懈词,一些計算機(jī)術(shù)語上的不專業(yè)歡迎大家指正蛇耀。我是學(xué)微電子的,大四的時候找了一家深圳的專業(yè)對口的公司坎弯,任職SMT工程師(殺馬特工程師0.0)纺涤,就是做電路板生產(chǎn)的,在車間上班的那種抠忘,做了一年多漸漸感覺前途一片迷茫~
轉(zhuǎn)機(jī)
在2015年3月份的時候撩炊,我有一個同學(xué)來深圳找工作,住在我們那里崎脉。后來找了一個iOS培訓(xùn)班拧咳,我就叫他給一份老師的課件,每天下班都看幾個小時代碼囚灼,不懂的問題就等他晚上回來問他骆膝。于是乎,博主從此走上iOS之路灶体。博主窮屌絲一個阅签,筆記本不是蘋果的,于是我就各種百度蝎抽,在win7下裝了一個虛擬機(jī)黑蘋果政钟,終于能跑Xcode了,晚上下班就一邊看課件一邊敲代碼樟结,終于做出了一個簡單的微信界面养交,心里還是挺高興的。后面用一個抓包工具paros抓取上架App的公共Api練習(xí)獲取網(wǎng)絡(luò)數(shù)據(jù)瓢宦,也能做出簡單的App层坠。
辭職告別SMT,入職加入iOS
經(jīng)過幾個月的苦學(xué)刁笙,覺得自己可以做App了,就果斷辭職谦趣,開始找工作疲吸。剛開始的時候投簡歷有回復(fù)的不是培訓(xùn)機(jī)構(gòu)就是電話里就拒絕了,感覺挺絕望的前鹅。但是功夫不負(fù)有心人摘悴,面試了一周終于有家公司想培養(yǎng)新人,于是就入職了舰绘。
然而蹂喻,我的老大在我入職的第四天就遞給我交接單離職高飛了
本來還想抱個大腿多學(xué)點技術(shù)的葱椭,無奈只能硬著頭皮上了。那時公司剛好有個智能手環(huán)的項目比較急口四,真是每天加班加點孵运,狼吞虎咽的消化新知識,特別是App第一次上線的那晚搞到半夜兩點才下班蔓彩。
總結(jié)及建議
1.并不是每個人都能像我這么幸運遇到一個接觸iOS的機(jī)會治笨,在此我要感謝我的那位同學(xué)。但是如果你感興趣或者想入門iOS赤嚼,只要你有C語言基礎(chǔ)就行旷赖,博主大學(xué)四年都是搞硬件開發(fā)的,就是用C語言編程控制單片機(jī)更卒,有C語言基礎(chǔ)上手iOS非车确酰快,因為Object C是C語言的超集也就是說他基于C語言蹂空,在此附上Object C程序設(shè)計PDF下載地址:
http://download.csdn.net/detail/longteng7878/8875929
2.其實開始對于OC里面的一些術(shù)語還是不太明白俯萌,不要緊,博主由于忙著做項目腌闯,第一個上線的項目是逼出來的绳瘟,有些代碼能理解就盡量理解,不能理解的做多了你自然就懂了姿骏,這是我個人的經(jīng)驗糖声。比如OC里面的對象,實例分瘦,類蘸泻,一開始老是弄混淆,現(xiàn)在基本上都理解了嘲玫。
3.當(dāng)你基本上把OC的書看得差不多的時候悦施,就可以開始你iOS的第一步了,如果你有條件就買個mac mini吧去团,也不貴抡诞,沒條件就和博主一樣,在win7裝個虛擬機(jī)黑蘋果土陪,Xcode這個軟件不難昼汗,有點英文基礎(chǔ)的人用起來都挺簡單,一般的開發(fā)軟件新建工程的步驟都差不多鬼雀,這里我就不啰嗦了顷窒。你可以網(wǎng)上找一些UI界面的demo,比如微信界面,試著自己敲代碼去搭建源哩,熟悉了UI一些基本控件的使用之后鞋吉,就可以用抓包工具paros鸦做,隨意在安卓市場上找簡單的App,抓取該App的公共Api谓着,用系統(tǒng)網(wǎng)絡(luò)請求或者AFNetworking方法獲取網(wǎng)絡(luò)數(shù)據(jù)泼诱。之后試著搭建這個App的界面并且獲取數(shù)據(jù),最后大致做出這個App漆魔。
此處附上簡單的微信界面demo:(代碼是博主從工程復(fù)制拷貝成的txt文件坷檩,有些地方如頭文件顯示不出來,請自行加上改抡,tableViewCell用Xib做的)
AppDelegate.h//? AppDelegate.h//? 自定義UITabBar#import@interface AppDelegate : UIResponder@property (strong, nonatomic) UIWindow *window;
@property(nonatomic,strong)UITabBarController *tabbarController;
@property(nonatomic,strong)UIView *customTabbarView;
-(void)hidenCustonmTabbarView;//隱藏
-(void)showCustonmTabbarView;//顯示
@end
AppDelegate.m
//? AppDelegate.m
//? 自定義UITabBar
#import "AppDelegate.h"
#import "OneViewController.h"
#import "TwoViewController.h"
#import "ThreeViewController.h"
#import "FourViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
//隱藏
-(void)hidenCustonmTabbarView
{
[UIView animateWithDuration:0.5 animations:^{
CGRect? rect =_customTabbarView.frame;
rect.origin.y=[UIScreen mainScreen].bounds.size.height;
_customTabbarView.frame =rect;
}];
}
//顯示
-(void)showCustonmTabbarView
{
[UIView animateWithDuration:0.5 animations:^{
CGRect? rect =_customTabbarView.frame;
rect.origin.y =[UIScreen mainScreen].bounds.size.height-49;
_customTabbarView.frame=rect;
}];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window =[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.window.backgroundColor =[UIColor whiteColor];
[self.window makeKeyAndVisible];
OneViewController *oneVC =[[OneViewController alloc]init];
TwoViewController *twoVC =[[TwoViewController alloc]init];
ThreeViewController *threeVC=[[ThreeViewController alloc]init];
FourViewController *fourVC=[[FourViewController alloc]init];
UINavigationController *oneNC =[[UINavigationController alloc]initWithRootViewController:oneVC];
UINavigationController *twoNC=[[UINavigationController alloc]initWithRootViewController:twoVC];
UINavigationController *threeNC=[[UINavigationController alloc]initWithRootViewController:threeVC];
UINavigationController *fourNC =[[UINavigationController alloc]initWithRootViewController:fourVC];
_tabbarController =[[UITabBarController alloc]init];
_tabbarController.viewControllers =@[oneNC,twoNC,threeNC,fourNC];
self.window.rootViewController? =_tabbarController;
//1矢炼、隱藏掉系統(tǒng)的tabbar
_tabbarController.tabBar.hidden=YES;
//2、自定義UIView 替換系統(tǒng)tabbarController.view
_customTabbarView =[[UIView alloc]init];
_customTabbarView.frame=CGRectMake(0, self.window.frame.size.height-49, self.window.frame.size.width, 49);
[_tabbarController.view addSubview:_customTabbarView];
//3阿纤、UIImageView
UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, _customTabbarView.frame.size.width, _customTabbarView.frame.size.height)];
imageView.image =[UIImage imageNamed:@"tabbarBkg@2x"];
[_customTabbarView addSubview:imageView];
//4句灌、設(shè)置View 上的button
int buttonWidth =self.window.frame.size.width/4;
NSArray *imageNames =[NSArray arrayWithObjects:@"tabbar_contacts@2x",@"tabbar_discover@2x",@"tabbar_mainframe@2x",@"tabbar_me@2x", nil];
NSArray *imageHLNames=[NSArray arrayWithObjects:@"tabbar_contactsHL@2x",@"tabbar_discoverHL@2x",@"tabbar_mainframeHL@2x",@"tabbar_meHL@2x", nil];
NSArray *titles=[NSArray arrayWithObjects:@"微信",@"發(fā)現(xiàn)",@"聯(lián)系人",@"我", nil];
for (int i=0; i<4; i++) {
UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
button.frame =CGRectMake(buttonWidth*i, 0, buttonWidth, 49);
//圖片
[button setBackgroundImage:[UIImage imageNamed:imageNames[i]] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:imageHLNames[i]] forState:UIControlStateSelected];
//文字
[button setTitle:titles[i] forState:UIControlStateNormal];
[button setTitleColor:[UIColor cyanColor] forState:UIControlStateSelected];
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:12]];
//文字偏移量
[button setTitleEdgeInsets:UIEdgeInsetsMake(30, 0, 0, 0)];
button.tag =i+1;
if (i==0) {
button.selected=YES;
}
[button? addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[_customTabbarView addSubview:button];
}
// Override point for customization after application launch.
return YES;
}
-(void)buttonClick:(UIButton *)button
{
//視圖切換
_tabbarController.selectedIndex =button.tag-1;
//清除原來的選中狀態(tài)
for (int i =0; i<4; i++) {
UIButton * selectbutton =(UIButton *) [_customTabbarView viewWithTag:i+1];
selectbutton.selected=NO;
}
button.selected =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:.
}
@end
OneViewController.m
//? OneViewController.m//? 自定義UITabBar
#import "OneViewController.h"
#import "NextViewController.h"
#import "AppDelegate.h"
@interface OneViewController (){
NSMutableArray *nameArray;
NSMutableArray *imageArray;
NSMutableArray *textArray;
UITableView *userTable;
NSInteger? currentRow;
}
@end
@implementation OneViewController
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
[app showCustonmTabbarView];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title =@"微信";
self.navigationController.navigationBar.barStyle =UIBarStyleBlack;
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"ShakeforsongBar_ios7@2x"] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.translucent =NO;
self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc]initWithTitle:@"編輯" style:UIBarButtonItemStylePlain target:self action:@selector(compile)];
nameArray =[NSMutableArray array];
imageArray =[NSMutableArray array];
textArray =[NSMutableArray array];
for (int i =0; i<13; i++) {
[nameArray addObject:[NSString stringWithFormat:@"好友%d",i]];
[imageArray addObject:[NSString stringWithFormat:@"test%d",i]];
[textArray addObject:[NSString stringWithFormat:@"我今天在上課 %d",i]];
}
//創(chuàng)建tableView
userTable =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64-49) style:UITableViewStylePlain];
userTable.delegate=self;
userTable.dataSource=self;
userTable.rowHeight=50;
[self.view addSubview:userTable];
}
-(void)compile
{
[userTable setEditing:!userTable.editing animated:YES];//打開編輯模式
}
#pragma mark - UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return nameArray.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier =@"Cell";
//identifier 標(biāo)識
//采用協(xié)議收購一個已經(jīng)分配的單元,以代替分配一個新的
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell ==nil) {
cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
//Subtitle 副標(biāo)題
}
cell.imageView.image =[UIImage imageNamed:imageArray[indexPath.row]];
cell.textLabel.text =nameArray[indexPath.row];
cell.detailTextLabel.text=textArray[indexPath.row];
return cell;
}
//設(shè)置tableView的編輯類型
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
//UITableViewCellEditingStyleDelete;
//UITableViewCellEditingStyleInsert;新增
}
//按照設(shè)置編輯類型來選擇是刪除還是新增
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//刪除
if (editingStyle ==UITableViewCellEditingStyleDelete) {
//先刪除數(shù)據(jù)源 再刪除單元格
[nameArray removeObjectAtIndex:indexPath.row];
[imageArray removeObjectAtIndex:indexPath.row];
[textArray removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}else if (editingStyle ==UITableViewCellEditingStyleInsert)
{
//新增
//先加數(shù)據(jù) 再新建單元格
[nameArray insertObject:@"我是新增的" atIndex:indexPath.row+1];
[imageArray insertObject:@"test10" atIndex:indexPath.row+1];
[textArray insertObject:@"逗你玩" atIndex:indexPath.row+1];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row+1 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
}
}
//修改刪除模式下刪除按鈕的文字
-(NSString*)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [NSString stringWithFormat:@"刪除"];
}
//單元格 移動
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
//起點
NSInteger fromRow =sourceIndexPath.row;
//終點
NSInteger toRow =destinationIndexPath.row;
;
//保存數(shù)據(jù)
NSString *name =nameArray[fromRow];
NSString *imageStr =imageArray[fromRow];
NSString *text =textArray[fromRow];
//刪除數(shù)據(jù)
[nameArray removeObjectAtIndex:fromRow];
[imageArray removeObjectAtIndex:fromRow];
[textArray removeObjectAtIndex:fromRow];
//插入數(shù)據(jù)
[nameArray insertObject:name atIndex:toRow];
[imageArray insertObject:imageStr atIndex:toRow];
[textArray insertObject:text atIndex:toRow];
//移動單元格
[tableView moveRowAtIndexPath:sourceIndexPath toIndexPath:destinationIndexPath];
//刷新表格
[tableView reloadData];
}
//單元格點擊
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//實例化appdelegate對象
AppDelegate *app =(AppDelegate *)[[UIApplication sharedApplication] delegate];
[app hidenCustonmTabbarView];
NextViewController *next =[[NextViewController alloc]init];
next.name = nameArray[indexPath.row];//正向傳值
next.delegate=self;
currentRow =indexPath.row;
[self.navigationController pushViewController:next animated:YES];
}
-(void)sendUserName:(NSString *)name
{
NSLog(@"name ====%@",name);
[nameArray replaceObjectAtIndex:currentRow withObject:name];
[userTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:currentRow inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
}
- (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
TwoViewController.m
//? TwoViewController.m//? 自定義UITabBar
#import "TwoViewController.h"
#import "Model.h"
@interface TwoViewController (){
NSMutableArray *dataArray;//tablView數(shù)據(jù)源
NSMutableArray *filterArry;//索引
NSMutableArray *searchArray;//保存搜索結(jié)果
UITableView *useTableView;
UISearchDisplayController *searchDisplay;
}
@end
@implementation TwoViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title =@"發(fā)現(xiàn)";
self.navigationController.navigationBar.barStyle =UIBarStyleBlack;
self.navigationController.navigationBar.translucent =NO;
[self dataSoure];//數(shù)據(jù)源
useTableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-49) style:UITableViewStylePlain];
useTableView.rowHeight =50;
useTableView.delegate =self;
useTableView.dataSource=self;
UISearchBar *searchBar =[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
searchBar.delegate=self;
useTableView.tableHeaderView =searchBar;
searchDisplay =[[UISearchDisplayController alloc]initWithSearchBar:searchBar contentsController:self];
searchDisplay.searchResultsDataSource=self;
searchDisplay.searchResultsDelegate =self;
searchDisplay.searchResultsTableView.rowHeight=120;
[self.view addSubview:useTableView];
// Do any additional setup after loading the view.
}
-(void)dataSoure
{
//MVC 設(shè)計模式
//高內(nèi)聚 低耦合? 代碼模塊重用度高
//M? 數(shù)據(jù)源 model V View? C? Controller
NSMutableArray *aArray =[NSMutableArray array];
NSMutableArray *bArray =[NSMutableArray array];
NSMutableArray *cArray =[NSMutableArray array];
NSMutableArray *dArray =[NSMutableArray array];
for (int i =0; i<7; i++) {
Model *model =[[Model alloc]init];
model.name =[NSString stringWithFormat:@"a%d",i];
model.imageName =[NSString stringWithFormat:@"test%d",i];
[aArray addObject:model];
}
for (int i =0; i<5; i++) {
Model *model =[[Model alloc]init];
model.name =[NSString stringWithFormat:@"b%d",i];
model.imageName =[NSString stringWithFormat:@"test%d",i];
[bArray addObject:model];
}
for (int i =0; i<8; i++) {
Model *model =[[Model alloc]init];
model.name =[NSString stringWithFormat:@"c%d",i];
model.imageName =[NSString stringWithFormat:@"test%d",i];
[cArray addObject:model];
}
for (int i =0; i<4; i++) {
Model *model =[[Model alloc]init];
model.name =[NSString stringWithFormat:@"c%d",i];
model.imageName =[NSString stringWithFormat:@"test%d",i];
[dArray addObject:model];
}
dataArray =[NSMutableArray arrayWithObjects:aArray,bArray,cArray,dArray, nil];
filterArry =[NSMutableArray arrayWithObjects:@"A",@"B",@"C",@"D", nil];
searchArray =[NSMutableArray array];
}
#pragma mark -UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView ==useTableView) {
return dataArray.count;
}
else
{
return 1;
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView ==useTableView) {
NSArray *arr =dataArray[section];
return arr.count;
}
else
{
return searchArray.count;
}
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *str =@"Cell";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:str];
if (cell ==nil) {
cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
}
//在數(shù)據(jù)源中取出Model
if (tableView ==useTableView) {
NSArray *arr =dataArray[indexPath.section];
Model *model =arr[indexPath.row];
cell.imageView.image =[UIImage imageNamed:model.imageName];
cell.textLabel.text =model.name;
}else
{
Model *model =searchArray[indexPath.row];
cell.textLabel.text =model.name;
cell.imageView.image =[UIImage imageNamed:model.imageName];
}
return cell;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return filterArry[section];
}
#pragma mark -UISeachDisPlayDelegate
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
NSLog(@"%@",searchText);
if (searchArray.count>0) {
[searchArray removeAllObjects];
}
for (NSArray *arr in dataArray) {
for (Model *model in arr) {
if ([model.name rangeOfString:searchText].location!=NSNotFound) {
NSLog(@"11111111");
[searchArray addObject:model];
NSLog(@"%@",searchArray);
}
}
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return filterArry;
}
//點擊某一個索引
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
NSLog(@"index ====%ld",index);
return index;
}
/*
#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
ThreeViewController.m
//? ThreeViewController.m//? 自定義UITabBar
#import "ThreeViewController.h"
#import "Model.h"
#import "TableViewCell.h"
@interface ThreeViewController (){
NSMutableArray *dataSoureArry;
UITableView *userTable;
}
@end
@implementation ThreeViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.barStyle =UIBarStyleBlack;
self.navigationController.navigationBar.translucent=NO;
self.title =@"發(fā)現(xiàn)";
[self getData];
userTable =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-49) style:UITableViewStyleGrouped];
userTable.rowHeight =70;
userTable.delegate=self;
userTable.dataSource=self;
[self.view addSubview:userTable];
}
-(void)getData
{
Model *model =[[Model alloc]init];
model.headImageName =@"ff_IconShowAlbum_ios7@2x";
model.name =@"朋友圈";
model.imageName =@"test6";
NSArray *aArray =[NSArray arrayWithObject:model];
NSMutableArray *bArray =[NSMutableArray array];
for (int i=0; i<2; i++) {
Model *model=[[Model alloc]init];
if (i==0) {
model.headImageName =@"ff_IconShowAlbum_ios7@2x";
model.name =@"掃一掃";
}
else
{
model.headImageName =@"ff_IconShake_ios7@2x";
model.name =@"搖一搖";
}
[bArray addObject:model];
}
NSMutableArray *cArray =[NSMutableArray array];
for (int i=0; i<2; i++) {
Model *model=[[Model alloc]init];
if (i==0) {
model.headImageName =@"ff_IconLocationService_ios7@2x";
model.name =@"附近的人";
}
else
{
model.headImageName =@"FriendCardNodeIconBottle@2x";
model.name =@"漂流瓶";
}
[cArray addObject:model];
}
NSMutableArray *dArray =[NSMutableArray array];
Model *gameModel =[[Model alloc]init];
gameModel.headImageName =@"MoreGame@2x";
gameModel.name =@"游戲";
[dArray addObject:gameModel];
dataSoureArry =[NSMutableArray arrayWithObjects:aArray,bArray,cArray,dArray, nil];
}
#pragma mark - UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return dataSoureArry.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSArray *arr =dataSoureArry[section];
return arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section ==0) {
TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell ==nil) {
cell =[[TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
NSArray *arr =[dataSoureArry objectAtIndex:indexPath.section];
Model *model =arr[indexPath.row];
[cell setModel:model];
//? [cell setIsShowRed:YES];
[cell showRed:YES];
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;//右箭頭
return cell;
}else
{
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (cell ==nil) {
cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
}
NSArray *arr =[dataSoureArry objectAtIndex:indexPath.section];
Model *model =arr[indexPath.row];
cell.imageView.image =[UIImage imageNamed:model.headImageName];
cell.textLabel.text =model.name;
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
}
- (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
FourViewController.m
//? FourViewController.m//? 自定義UITabBar
#import "FourViewController.h"
#import "Model.h"
#import "Cell.h"
#import "TableViewCell.h"
@interface FourViewController (){
NSMutableArray *_dataSoureArray;
UITableView *userTableView;
}
@end
@implementation FourViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title=@"我";
self.navigationController.navigationBar.barStyle =UIBarStyleBlack;
self.navigationController.navigationBar.translucent =NO;
[self getData];//加載數(shù)據(jù)
userTableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-49) style:UITableViewStyleGrouped];
userTableView.delegate=self;
userTableView.dataSource =self;
//注冊xib單元格
[userTableView registerNib:[UINib nibWithNibName:@"Cell" bundle:nil] forCellReuseIdentifier:@"oneCell"];//按照XIB文件注冊
// [userTableView registerClass:[TableViewCell class] forCellReuseIdentifier:@"Cell"]; //按照類名注冊
userTableView .rowHeight =50;
[self.view addSubview:userTableView];
}
#pragma mark -UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return _dataSoureArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSArray *arr =_dataSoureArray[section];
return arr.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Cell *cell =[tableView dequeueReusableCellWithIdentifier:@"oneCell"];
NSArray *arr =_dataSoureArray[indexPath.section];
Model *model =arr[indexPath.row];
cell.headImageView.image =[UIImage imageNamed:model.headImageName];
cell.nameLabel.text =model.name;
cell.friendImageView.image =[UIImage imageNamed:model.imageName];
return cell;
}
-(void)getData
{
Model *model =[[Model alloc]init];
model.headImageName =@"ff_IconShowAlbum_ios7@2x";
model.name =@"朋友圈";
model.imageName =@"test6";
NSArray *aArray =[NSArray arrayWithObject:model];
NSMutableArray *bArray =[NSMutableArray array];
for (int i=0; i<3; i++) {
Model *model=[[Model alloc]init];
if (i==0) {
model.headImageName =@"MoreMyAlbum_ios7@2x";
model.name =@"相冊";
}
else if(i==1)
{
model.headImageName =@"MoreMyFavorites_ios7@2x";
model.name =@"收藏";
}
else{
model.headImageName=@"MoreMyBankCard_ios7@2x";
model.name =@"銀行卡";
}
[bArray addObject:model];
}
NSMutableArray *cArray =[NSMutableArray array];
Model *myModel=[[Model alloc]init];
myModel.headImageName =@"MoreMySafe_ios7@2x";
myModel.name =@"安全";
[cArray addObject:myModel];
NSMutableArray *dArray =[NSMutableArray array];
Model *gameModel =[[Model alloc]init];
gameModel.headImageName =@"MoreSetting_ios7@2x";
gameModel.name =@"設(shè)置";
[dArray addObject:gameModel];
_dataSoureArray =[NSMutableArray arrayWithObjects:aArray,bArray,cArray,dArray, nil];
}
- (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
NextViewController.h
//? NextViewController.h//? 自定義UITabBar
#import
//聲明協(xié)議
@protocol NextViewControllerDelegate
//定義方法
-(void)sendUserName:(NSString*)name;
@end
@interface NextViewController : UIViewController
@property(nonatomic,strong)NSString *name;
//協(xié)議對象
@property(nonatomic,weak)iddelegate;
@end
NextViewController.m
//? NextViewController.m
//? 自定義UITabBar
#import "NextViewController.h"
@interface NextViewController ()
{
UITextField *textField ;
}
@end
@implementation NextViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@" %@",self.name);
textField =[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 200, 30)];
textField.borderStyle=UITextBorderStyleRoundedRect;
textField.text =self.name;
self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(Click)];
[self.view addSubview:textField];
// Do any additional setup after loading the view.
}
-(void)Click
{
NSString *str =[NSString stringWithFormat:@"%@",textField.text];
//判斷協(xié)議對象和協(xié)議方法是不是被響應(yīng)
if (_delegate&&[_delegate respondsToSelector:@selector(sendUserName:)]) {
[_delegate sendUserName:str];
}
[self.navigationController popToRootViewControllerAnimated: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
Model.h
//? Model.h//? 自定義UITabBar
#import
@interface Model : NSObject
@property (nonatomic,strong)NSString *imageName;
@property (nonatomic,strong)NSString *name;
@property (nonatomic,strong)NSString *headImageName;
@end
TableViewCell.h
//? TableViewCell.h//? 自定義UITabBar
#import#
import "Model.h"
@interface TableViewCell : UITableViewCell
@property (nonatomic,strong)UIImageView *headImageView;
@property (nonatomic,strong)UIImageView *fridendImageView;
@property (nonatomic,strong)UILabel *nameLabel;
@property (nonatomic,assign)BOOL isShowRed;
-(void)setModel:(Model*)model;//數(shù)據(jù)
-(void)showRed:(BOOL)isShowRed;//是否顯示紅點
@end
TableViewCell.m
//? TableViewCell.m
//? 自定義UITabBar
#import "TableViewCell.h"
@implementation TableViewCell
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self =[super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
//頭像
_headImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 25, 30, 30)];
//名字
_nameLabel =[[UILabel alloc]initWithFrame:CGRectMake(50, 25, 100, 30)];
_nameLabel.font =[UIFont boldSystemFontOfSize:17];
//朋友圈頭像
_fridendImageView =[[UIImageView alloc]initWithFrame:CGRectMake(280, 10, 50, 50)];
[self.contentView addSubview:_fridendImageView];
[self.contentView addSubview:_nameLabel];
[self.contentView addSubview:_headImageView];
}
return self;
}
-(void)setModel:(Model *)model
{
//頭像
_headImageView.image =[UIImage imageNamed:model.headImageName];
_nameLabel.text=model.name;
_fridendImageView.image =[UIImage imageNamed:model.imageName];
}
-(void)showRed:(BOOL)isShowRed
{
//如果是顯示
if (isShowRed) {
int width =20;
UIImageView *redImageView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"AlbumNewNotify_ios7@2x"]];
redImageView.frame =CGRectMake(_fridendImageView.frame.size.width-width/2, _fridendImageView.frame.origin.y-width, width, width);
[_fridendImageView addSubview:redImageView];
}
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
4.當(dāng)你能基本完成以上幾點的時候,就可以試著找工作了,如果你是科班出身找工作會比較好找洲愤,不是科班出身也不用驚慌吕粹,博主就是學(xué)硬件的践叠,一樣可以找得到。面試的時候能答出一些基本的問題,只要你態(tài)度夠誠懇,工資方面壓低一些格带,一般都沒什么問題的。先入門刹枉,進(jìn)入一個平臺實習(xí)叽唱,以后工資會漲得很快的。
總結(jié)一下:只要你感興趣微宝,努力用心去學(xué)棺亭,沒有什么做不到的。(以上一些關(guān)于在iOS實際應(yīng)用中遇到的問題博主會逐漸更新蟋软,盡請期待O庹)
越努力,越幸運岳守!
以現(xiàn)在大多數(shù)人的努力程度之低钉稍,根本輪不到可以拼天賦。
(第一次寫簡書棺耍,有什么不足之處歡迎指正!)