博客> 谈谈一些自学iOS入门的经验吧
谈谈一些自学iOS入门的经验吧
2017-11-25 07:46 评论:0 阅读:558 czkyes
ios 入门 经验

###前言 最近忙完项目比较闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助。 博主非科班出身,一些计算机术语上的不专业欢迎大家指正。 我是学微电子的,大四的时候找了一家深圳的专业对口的公司,任职SMT工程师(杀马特工程师0.0),就是做电路板生产的,在车间上班的那种,做了一年多渐渐感觉前途一片迷茫~

###转机 在2015年3月份的时候,我有一个同学来深圳找工作,住在我们那里。后来找了一个iOS培训班,我就叫他给一份老师的课件,每天下班都看几个小时代码,不懂的问题就等他晚上回来问他。于是乎,博主从此走上iOS之路。

博主穷屌丝一个,笔记本不是苹果的,于是我就各种百度,在win7下装了一个虚拟机黑苹果,终于能跑Xcode了,晚上下班就一边看课件一边敲代码,终于做出了一个简单的微信界面,心里还是挺高兴的。后面用一个抓包工具paros抓取上架App的公共Api练习获取网络数据,也能做出简单的App。

###辞职告别SMT,入职加入iOS 经过几个月的苦学,觉得自己可以做App了,就果断辞职,开始找工作。刚开始的时候投简历有回复的不是培训机构就是电话里就拒绝了,感觉挺绝望的。但是功夫不负有心人,面试了一周终于有家公司想培养新人,于是就入职了。

然而,我的老大在我入职的第四天就递给我交接单离职高飞了~  A0TXT2EZUZJ4_@$Z9L}(BLT.jpg 本来还想抱个大腿多学点技术的,无奈只能硬着头皮上了。那时公司刚好有个智能手环的项目比较急,真是每天加班加点,狼吞虎咽的消化新知识,特别是App第一次上线的那晚搞到半夜两点才下班。

总结及建议

1.并不是每个人都能像我这么幸运遇到一个接触iOS的机会,在此我要感谢我的那位同学。但是如果你感兴趣或者想入门iOS,只要你有C语言基础就行,博主大学四年都是搞硬件开发的,就是用C语言编程控制单片机,有C语言基础上手iOS非常快,因为Object C是C语言的超集也就是说他基于C语言,在此附上Object C程序设计PDF下载地址: Enter your link description here:

2.其实开始对于OC里面的一些术语还是不太明白,不要紧,博主由于忙着做项目,第一个上线的项目是逼出来的,有些代码能理解就尽量理解,不能理解的做多了你自然就懂了,这是我个人的经验。比如OC里面的对象,实例,类,一开始老是弄混淆,现在基本上都理解了。

3.当你基本上把OC的书看得差不多的时候,就可以开始你iOS的第一步了,如果你有条件就买个mac mini吧,也不贵,没条件就和博主一样,在win7装个虚拟机黑苹果,Xcode这个软件不难,有点英文基础的人用起来都挺简单,一般的开发软件新建工程的步骤都差不多,这里我就不啰嗦了。你可以网上找一些UI界面的demo,比如微信界面,试着自己敲代码去搭建,熟悉了UI一些基本控件的使用之后,就可以用抓包工具paros,随意在安卓市场上找简单的App,抓取该App的公共Api,用系统网络请求或者AFNetworking方法获取网络数据。之后试着搭建这个App的界面并且获取数据,最后大致做出这个App。 此处附上简单的微信界面demo:(代码是博主从工程复制拷贝成的txt文件,有些地方如头文件显示不出来,请自行加上)

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、隐藏掉系统的tabbar

    _tabbarController.tabBar.hidden=YES; //2、自定义UIView 替换系统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、设置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:@"微信",@"发现",@"联系人",@"我", nil];

    for (int i=0; i<4 button =[UIButton button.frame =CGRectMake(buttonWidth*i, button.tag =i+1; xss=removed button.selected=YES; tabbarController.selectedIndex =button.tag-1; i =0; selectbutton =(UIButton selectbutton.selected=NO; button.selected =YES;> { 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 userTable =[[UITableView userTable.delegate=self; userTable.dataSource=self; userTable.rowHeight=50; identifier =@ cell =[tableView xss=removed cell =[[UITableViewCell cell.imageView.image =[UIImage cell.textLabel.text =nameArray[indexPath.row]; cell.detailTextLabel.text=textArray[indexPath.row]; xss=removed xss=removed fromRow =sourceIndexPath.row; toRow =destinationIndexPath.row; name =nameArray[fromRow]; imageStr =imageArray[fromRow]; text =textArray[fromRow]; app =(AppDelegate next =[[NextViewController xss=removed next.delegate=self; currentRow =indexPath.row; xss=removed>

{ NSMutableArray dataArray;//tablView数据源 NSMutableArray filterArry;//索引 NSMutableArray searchArray;//保存搜索结果 UITableView useTableView; UISearchDisplayController *searchDisplay;

}

@end

@implementation TwoViewController

  • (void)viewDidLoad { [super viewDidLoad]; self.title =@"发现"; self.navigationController.navigationBar.barStyle =UIBarStyleBlack; self.navigationController.navigationBar.translucent =NO; [self dataSoure];//数据源

    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 设计模式 //高内聚 低耦合 代码模块重用度高 //M 数据源 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 model =[[Model model.name =[NSString model.imageName =[NSString i =0; model =[[Model model.name =[NSString model.imageName =[NSString i =0; model =[[Model model.name =[NSString model.imageName =[NSString i =0; model =[[Model model.name =[NSString model.imageName =[NSString dataArray =[NSMutableArray filterArry =[NSMutableArray searchArray =[NSMutableArray xss=removed xss=removed arr =dataArray[section]; str =@ cell =[tableView xss=removed cell =[[UITableViewCell xss=removed arr =dataArray[indexPath.section]; model =arr[indexPath.row]; cell.imageView.image =[UIImage cell.textLabel.text =model.name; model =searchArray[indexPath.row]; cell.textLabel.text =model.name; cell.imageView.image =[UIImage>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.h 无

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 =@"发现"; [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 model=[[Model xss=removed model.headImageName =@ model.name =@ model.headImageName =@ model.name =@ cArray =[NSMutableArray i=0; model=[[Model xss=removed model.headImageName =@ model.name =@ model.headImageName =@ model.name =@ dArray =[NSMutableArray gameModel =[[Model gameModel.headImageName =@ gameModel.name =@ dataSoureArry =[NSMutableArray arr =dataSoureArry[section]; xss=removed cell=[tableView xss=removed cell =[[TableViewCell arr =[dataSoureArry model =arr[indexPath.row]; cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;//右箭头 cell =[tableView xss=removed cell =[[UITableViewCell arr =[dataSoureArry model =arr[indexPath.row]; cell.imageView.image =[UIImage cell.textLabel.text =model.name; cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;>

{ 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];//加载数据

    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 model=[[Model xss=removed model.headImageName =@ model.name =@ xss=removed model.headImageName =@ model.name =@ model.headImageName=@ model.name =@ cArray =[NSMutableArray myModel=[[Model myModel.headImageName =@ myModel.name =@ dArray =[NSMutableArray gameModel =[[Model gameModel.headImageName =@ gameModel.name =@ dataSoureArray =[NSMutableArray>

//声明协议 @protocol NextViewControllerDelegate

//定义方法 -(void)sendUserName:(NSString*)name;

@end

@interface NextViewController : UIViewController

@property(nonatomic,strong)NSString *name; //协议对象 @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];

//判断协议对象和协议方法是不是被响应

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

Model.m 无


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;//数据

-(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.当你能基本完成以上几点的时候,就可以试着找工作了,如果你是科班出身找工作会比较好找,不是科班出身也不用惊慌,博主就是学硬件的,一样可以找得到。面试的时候能答出一些基本的问题,只要你态度够诚恳,工资方面压低一些,一般都没什么问题的。先入门,进入一个平台实习,以后工资会涨得很快的。

总结一下:只要你感兴趣,努力用心去学,没有什么做不到的。(以上一些关于在iOS实际应用中遇到的问题博主会逐渐更新,尽请期待!)

越努力,越幸运!
以现在大多数人的努力程度之低,根本轮不到可以拼天赋。

                                                                                            (第一次写博客,有什么不足之处欢迎指正!)
收藏
1
sina weixin mail 回到顶部