谈谈一些入门iOS的经验吧

前言

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

转机

在2015年3月份的时候,我有一个同学来深圳找工作,住在我们那里。后来找了一个iOS培训班,我就叫他给一份老师的课件,每天下班都看几个小时代码,不懂的问题就等他晚上回来问他。于是乎,博主从此走上iOS之路。博主穷屌丝一个,笔记本不是苹果的,于是我就各种百度,在win7下装了一个虚拟机黑苹果,终于能跑Xcode了,晚上下班就一边看课件一边敲代码,终于做出了一个简单的微信界面,心里还是挺高兴的。后面用一个抓包工具paros抓取上架App的公共Api练习获取网络数据,也能做出简单的App。

辞职告别SMT,入职加入iOS

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

然而,我的老大在我入职的第四天就递给我交接单离职高飞了


本来还想抱个大腿多学点技术的,无奈只能硬着头皮上了。那时公司刚好有个智能手环的项目比较急,真是每天加班加点,狼吞虎咽的消化新知识,特别是App第一次上线的那晚搞到半夜两点才下班。

总结及建议

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

http://download.csdn.net/detail/longteng7878/8875929

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

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

此处附上简单的微信界面demo:(代码是博主从工程复制拷贝成的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、隐藏掉系统的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; 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;

//清除原来的选中状态

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]];

}

//创建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 标识

//采用协议收购一个已经分配的单元,以代替分配一个新的

UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:identifier];

if (cell ==nil) {

cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];

//Subtitle 副标题

}

cell.imageView.image =[UIImage imageNamed:imageArray[indexPath.row]];

cell.textLabel.text =nameArray[indexPath.row];

cell.detailTextLabel.text=textArray[indexPath.row];

return cell;

}

//设置tableView的编辑类型

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

return UITableViewCellEditingStyleDelete;

//UITableViewCellEditingStyleDelete;

//UITableViewCellEditingStyleInsert;新增

}

//按照设置编辑类型来选择是删除还是新增

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

//删除

if (editingStyle ==UITableViewCellEditingStyleDelete) {

//先删除数据源 再删除单元格

[nameArray removeObjectAtIndex:indexPath.row];

[imageArray removeObjectAtIndex:indexPath.row];

[textArray removeObjectAtIndex:indexPath.row];

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

}else if (editingStyle ==UITableViewCellEditingStyleInsert)

{

//新增

//先加数据 再新建单元格

[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;

;

//保存数据

NSString *name =nameArray[fromRow];

NSString *imageStr =imageArray[fromRow];

NSString *text =textArray[fromRow];

//删除数据

[nameArray removeObjectAtIndex:fromRow];

[imageArray removeObjectAtIndex:fromRow];

[textArray removeObjectAtIndex:fromRow];

//插入数据

[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数据源

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; 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];

}

//在数据源中取出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 =@"发现";

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

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 =@"设置";

[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

//声明协议

@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

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实际应用中遇到的问题博主会逐渐更新,尽请期待!)

越努力,越幸运!

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

(第一次写简书,有什么不足之处欢迎指正!)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 195,719评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,337评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 142,887评论 0 324
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,488评论 1 266
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,313评论 4 357
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,284评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,672评论 3 386
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,346评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,644评论 1 293
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,700评论 2 312
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,457评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,316评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,706评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,990评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,261评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,648评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,859评论 2 335

推荐阅读更多精彩内容