你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> 談談入門iOS的經驗吧

談談入門iOS的經驗吧

編輯: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實際應用中遇到的問題博主會逐漸更新,盡請期待!)

越努力,越幸運! 

 
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved