Iphone 开发笔记(有点乱,零碎,脑子记忆力不好,只好写下来了。。,大部分内容都是word...

Iphone 开发笔记

 

 

 

/////////////////////////////////////////////////////////////////

// 基本框架

/////////////////////////////////////////////////////////////////

 

基本框架:

Library  一些帮助类

   --UserLib  用户自定义帮助类

   --Lib      特定功能的帮助类

Modal   实体

Images   图片

Rescources     ui

Classes   ui.h.m文件

ui的命名以Controller结尾,StationFunctionController.xib

 

 

导航应用程序的创建:

 

1.创建导航的页面的ui

    -- .xib  ( empty interface )

-- .h  ( Objective-C class )

-- .m

修改.h文件,使它继承UIViewController

修改.xib文件,选择File’s Owner,修改Calss 之前创建的.h

 

2.AppDelegate.h中实例化UITabBarController , UITabBar , UINavigationController(有几个导航页面就实例几个UINavigationController对象)

#import <UIKit/UIKit.h>

#import <Foundation/Foundation.h>

#import <QuartzCore/QuartzCore.h>

#import "StationFunctionController.h"

#import "CompanyInformationController.h"

#import "PersonalInformationController.h"

#import "plistReader.h"

#import "LoginController.h"

#import "CompanyChooseController.h"

#import "TabBarController.h"

#import "MyTabBarDelegate.h"

#import "LogoutController.h"

int isReloadsf;

int isReloadci;

int isReloadpi;

int isReloadlo;

@interface AppDelegate : NSObject <UIApplicationDelegate,UITabBarControllerDelegate,MyTabBarDelegate>{

    TabBarController *tabController;

    UITabBar *tabBar;

    UINavigationController *stationFunNav;

    UINavigationController *companyInfoNav;

    UINavigationController *personalInfoNav;

    UINavigationController *logoutNav;

    UITextField *accountField;

    UITextField *passwdField;

    

}

@property (strong, nonatomic) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet UITabBarController *tabController;

@property (nonatomic, retain) IBOutlet UITabBar *tabBar;

-(void)LoadTab;

-(void)IsLogin;

@end

 

注:需要创建MainWindow.xib,布局如下:

其中的App Delegate是一个ObjectclassAppDelegate

 

3.接下来就是设置uitabbarcontroller,附上代码:

-(void)LoadTab{

   

    //页面对象

    StationFunctionController *sfController = [[StationFunctionController alloc]initWithNibName:@"StationFunctionController" bundle:nil];

    CompanyInformationController *ciController = [[CompanyInformationController alloc]initWithNibName:@"CompanyInformationController" bundle:nil];

    PersonalInformationController *piController = [[PersonalInformationController alloc]initWithNibName:@"PersonalInformationController" bundle:nil];

   

   

   

    //实例navgationController

    stationFunNav = [[UINavigationController alloc] initWithRootViewController:sfController];

    companyInfoNav = [[UINavigationController alloc] initWithRootViewController:ciController];

    personalInfoNav = [[UINavigationController alloc] initWithRootViewController:piController];

   

    //stationFunNav.navigationBar.tintColor = [UIColor colorWithRed:0.0f green:0.55f blue:0.60f alpha:1.0f];

    //companyInfoNav.navigationBar.tintColor = [UIColor colorWithRed:0.0f green:0.55f blue:0.60f alpha:1.0f];

    //personalInfoNav.navigationBar.tintColor = [UIColor colorWithRed:0.0f green:0.55f blue:0.60f alpha:1.0f];

   

    UITabBarItem *sfItem = [[UITabBarItem alloc]initWithTitle:@"站内功能" image:[UIImage imageNamed:@".."] tag:0];

    UITabBarItem *ciItem = [[UITabBarItem alloc]initWithTitle:@"公司信息" image:[UIImage imageNamed:@".."] tag:1];

    UITabBarItem *piItem = [[UITabBarItem alloc]initWithTitle:@"个人信息" image:[UIImage imageNamed:@".."] tag:2];

    //UITabBarItem *logoutItem = [[UITabBarItem alloc]initWithTitle:@"退出" image:[UIImage imageNamed:@""] tag:3];

   

    stationFunNav.tabBarItem = sfItem;

    companyInfoNav.tabBarItem = ciItem;

    personalInfoNav.tabBarItem = piItem;

   

   

    NSArray *array = [NSArray arrayWithObjects:stationFunNav,companyInfoNav,personalInfoNav,nil];

    tabController = [[UITabBarController alloc]init];

    tabController.viewControllers = array;

    tabController.delegate = self;

    [_window addSubview:tabController.view];

    [self.window makeKeyAndVisible];

   

   

    [sfItem release];

    [ciItem release];

    [piItem release];

    [sfController release];

    [ciController release];

    [piController release];

    [stationFunNav release];

    [companyInfoNav release];

    [personalInfoNav release];

   

   

}

 

didFinishLaunchingWithOptions方法中调用它。

下面是AppDelegate.h / .m 文件的全部代码:

//

//  AppDelegate.m

//  GPSAttendance

//

//  Created by Logictech on 12-4-23.

//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.

//

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;

@synthesize tabController;

@synthesize tabBar;

- (void)dealloc

{

    [tabController release];

    [tabBar release];

    [stationFunNav release];

    [companyInfoNav release];

    [personalInfoNav release];

    [logoutNav release];

    

    [_window release];

    [super dealloc];

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor whiteColor];

    //[self.window makeKeyAndVisible];

    

    [self LoadTab];

    

    return 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:.

     */

}

//////////////////////

//  加载 tabController

//////////////////////

-(void)LoadTab{

    tabBar = [[UITabBar alloc]init];

    tabController = [[TabBarController alloc]init];

    tabController.myTabBarDelegate = self;

    

    //页面对象

    StationFunctionController *sfController = [[StationFunctionController alloc]initWithNibName:@"StationFunctionController" bundle:nil];

    CompanyInformationController *ciController = [[CompanyInformationController alloc]initWithNibName:@"CompanyInformationController" bundle:nil];

    PersonalInformationController *piController = [[PersonalInformationController alloc]initWithNibName:@"PersonalInformationController" bundle:nil];

    LogoutController *loController = [[LogoutController alloc]initWithNibName:@"LogoutController" bundle:nil];

    

    

    //实例navgationController

    stationFunNav = [[UINavigationController alloc] initWithRootViewController:sfController];

    companyInfoNav = [[UINavigationController alloc] initWithRootViewController:ciController];

    personalInfoNav = [[UINavigationController alloc] initWithRootViewController:piController];

    logoutNav = [[UINavigationController alloc] initWithRootViewController:loController];

    

    stationFunNav.navigationBar.tintColor = [UIColor colorWithRed:0.14f green:0.44f blue:0.53f alpha:1.0f]; 

    companyInfoNav.navigationBar.tintColor = [UIColor colorWithRed:0.14f green:0.44f blue:0.53f alpha:1.0f]; 

    personalInfoNav.navigationBar.tintColor = [UIColor colorWithRed:0.14f green:0.44f blue:0.53f alpha:1.0f]; 

    logoutNav.navigationBar.tintColor = [UIColor colorWithRed:0.14f green:0.44f blue:0.53f alpha:1.0f]; 

    

    UITabBarItem *sfItem = [[UITabBarItem alloc]initWithTitle:@"站内功能" image:[UIImage imageNamed:@"Home.png"] tag:0];

    UITabBarItem *ciItem = [[UITabBarItem alloc]initWithTitle:@"公司信息" image:[UIImage imageNamed:@"Globe.png"] tag:1];

    UITabBarItem *piItem = [[UITabBarItem alloc]initWithTitle:@"个人信息" image:[UIImage imageNamed:@"BusinessMan.png"] tag:2];

    UITabBarItem *logoutItem = [[UITabBarItem alloc]initWithTitle:@"退出" image:[UIImage imageNamed:@"Exit.png"] tag:3];

    

    stationFunNav.tabBarItem = sfItem;

    companyInfoNav.tabBarItem = ciItem;

    personalInfoNav.tabBarItem = piItem;

    logoutNav.tabBarItem = logoutItem;

    

    /*

    if([[plistReader doRead:@"company_P" index:0] isEqualToString:@""] || [plistReader doRead:@"company_P" index:0] == nil){

        

        stationFunNav.tabBarItem.enabled = NO;

        companyInfoNav.tabBarItem.enabled = NO;

        personalInfoNav.tabBarItem.enabled = NO;

        logoutNav.tabBarItem.enabled = NO;

    }

     

     UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"backgroundImage.png"]];

     img.frame = CGRectMake(0, 0,

     self.defaultTabBarController.tabBar.frame.size.width,                                             self.defaultTabBarController.tabBar.frame.size.height);

     img.contentMode = UIViewContentModeScaleToFill;

     [[[self defaultTabBarController] tabBar] insertSubview:img atIndex:0];

     [img release];

     

    */

    

    NSArray *array = [NSArray arrayWithObjects:stationFunNav,companyInfoNav,personalInfoNav,logoutNav,nil];

    tabController.viewControllers = array;

    tabController.delegate = self;

    [_window addSubview:tabController.view];

    [self.window makeKeyAndVisible];

    

    UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image1.jpg"]];

    img.frame = CGRectMake(0, 0, tabController.tabBar.frame.size.width, tabController.tabBar.frame.size.height);

    img.contentMode = UIViewContentModeScaleToFill;

    [tabController.tabBar insertSubview:img atIndex:0];

    [img release];

    

    

    //判断是否登录

    //[self IsLogin];

    

    

    

    [sfItem release];

    [ciItem release];

    [piItem release];

    [logoutItem release];

    [sfController release];

    [ciController release];

    [piController release];

    [loController release];

    

}

-(void)IsChooseCompany:(BOOL)isChooseCompany{

    /*

    if(!isChooseCompany){

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"请选择您的公司" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil];

        [alert show];

        [alert release];

    }

     */

}

//////////////////////

//  判断是否登录

//////////////////////

-(void)IsLogin{

    CATransition *cityTrans = [CATransition animation];

    cityTrans.duration = 0.5f;

    cityTrans.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];

    cityTrans.type = kCATransitionMoveIn;

    cityTrans.subtype = kCATransitionFromBottom;

    cityTrans.delegate = self;

    

    //如果没有登录

    if ([[plistReader doRead:@"phoneNum_P" index:1] isEqualToString:@""] || ([plistReader doRead:@"phoneNum_P" index:1] == nil)) {

        

        LoginController *loginController = [[LoginController alloc]initWithNibName:@"LoginController" bundle:nil];

        [stationFunNav.view.layer addAnimation:cityTrans forKey:nil];

        [stationFunNav presentModalViewController:loginController animated:YES];

        [loginController release];

    }

}

@end

 

 

/////////////////////////////////////////////////////////////////

// 关于Login 页面

/////////////////////////////////////////////////////////////////

判断指定plist文件中是否有你想要的数据来弹出登录页面

(网上有这么一段话:

window中不要添加多个subview如想跳UINavigationControllerpush方法push一个新的UIViewController或者使用UIViewControllerpresentModelViewController方法来出一个新的注意此面会遮住下面的tab bar

[UIWindow addSubview]
的缺点除了第一个被add去的view之外其他由UIViewController控制的新添加view均无法接收屏幕旋delegate第二直接add一个subview效果上是突然转换成了另一个界面略差而且也会住下面的tab barview是被addwindow中从而使window中第一个view到了back新的view到了front从而tab bar消失

 

)

 

 

使用 presentModalViewController方法或许效果比pushview好点:

presentModalViewController:

[stationFunNav presentModalViewController:loginController animated:YES];

 

pushViewController:

        [stationFunNav pushViewController:loginController animated:YES];

 

 

还有是alertview的登录弹出框(MAlertView是一个继承UIAlerView.h.m

//设置登录

        accountField = [[UITextField alloc]init];

        passwdField = [[UITextField alloc]init];

        //设置密码框

        [passwdField setSecureTextEntry:YES];

        MAlertView *alertLogin = [[MAlertView alloc] initWithTitle:@"登录" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];

        [alertLogin addTextField:accountField placeHolder:@"这里输入用户ID"];

        [alertLogin addTextField:passwdField placeHolder:@"这里输入密码"];

        [alertLogin show];

 

 

 

presentModalViewController出来的页面用dismissModalViewControllerAnimated来关闭

 

 

 

 

关于<libxml/tree.h>

bulid -> Header Search Paths 添加/usr/include/libxml2

 

 

代码添加uibutton

UIButton* button = [UIButton buttonWithType:100];

    button.frame = CGRectMake(12,12,70,30);

    [button setTitle:@"考勤" forState:UIControlStateNormal];

    // 注册按钮按下时的处理函数

    [button addTarget:self action:@selector(countup:)

     forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button];

 

buttontype 可以尝试着用数字试试,(似乎是私有api的写法)

 

关于自定义的cell

在设置xib时,File’s Ownerobject , uitabviewcell 为你自定义的class

引用的时候:

dateChooseCell = (DateSelectCell *)[tableView dequeueReusableCellWithIdentifier:@"DateSelectCell"];

 

    NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"DateSelectCell" owner:self options:nil];

        dateChooseCell = [nib objectAtIndex:0];

关闭键盘

 

    [tfldMedicineName resignFirstResponder];

获得焦点,打开键盘

    [txtUserID becomeFirstResponder];

 

增加动画

#import <QuartzCore/QuartzCore.h>

 

CGContextRef context = UIGraphicsGetCurrentContext();

        [UIView beginAnimations:nil context:context];

        [UIView setAnimationDuration:0.5f];

        [UIView setAnimationDelegate:self];

        button.frame = CGRectMake(20,6,80,30);

        button.alpha = 1;

        button01.frame = CGRectMake(120,6,80,30);

        button01.alpha = 1;

        button02.frame = CGRectMake(220,6,80,30);

        button02.alpha = 1;

        [tableview setFrame:CGRectMake(0.0f, 30.0f, 320.0f, 420.0f)];

        [UIView commitAnimations];

 

//动画结束时

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag{}

 

 

背景的渐变色(还是用图片吧..

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];

 

 

iPhone开发中各种动画翻页效果整理

iphone中存在很多好看的动画效果,用于页面的切换等。其中某些是apple私有的,据说私有的无法通过apple的审批。 最近工作中刚好用到过其中的某些动画,所以在网上搜了下资料,了解了下这些动画。这里就自己的理解做一下总结。

UIView 动画

官方API中,使用UIView可以设置5个动画效果,分别为:

UIViewAnimationTransitionNone    不使用动画 UIViewAnimationTransitionFlipFromLeft    从左向右旋转翻页 UIViewAnimationTransitionFlipFromRight    从右向左旋转翻页,与UIViewAnimationTransitionFlipFromLeft相反 UIViewAnimationTransitionCurlUp    卷曲翻页,从下往上 UIViewAnimationTransitionCurlDown    卷曲翻页,从上往下

详细请参见UIViewAnimationTransition,举例如下:

[UIView beginAnimations:@"animationID" context:nil];//开始一个动画块,第一个参数为动画块标识 [UIView setAnimationDuration:0.5f];//设置动画的持续时间 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //设置动画块中的动画属性变化的曲线,此方法必须在beginAnimations方法和commitAnimations,默认即为UIViewAnimationCurveEaseInOut效果。 //详细请参见UIViewAnimationCurve [UIView setAnimationRepeatAutoreverses:NO];//设置是否自动反转当前的动画效果 [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES]; //设置过渡的动画效果,此处第一个参数可使用上面5种动画效果。 [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];//页面翻转 [UIView commitAnimations];//提交动画

公共动画效果

使用CATransiton可以设置4种动画效果,分别为:

NSString * const kCATransitionFade;//渐渐消失 NSString * const kCATransitionMoveIn;//覆盖进入 NSString * const kCATransitionPush;//推出 NSString * const kCATransitionReveal;//MoveIn相反

举例说明:

CATransition *animation = [CATransition animation]; animation.duration = 0.5f; animation.timingFunction = UIViewAnimationCurveEaseInOut;  animation.type = kCATransitionPush;//设置上面4种动画效果 animation.subtype = kCATransitionFromTop;//设置动画的方向,有四种,分别为kCATransitionFromRightkCATransitionFromLeftkCATransitionFromTopkCATransitionFromBottom  [self.view.layer addAnimation:animation forKey:@"animationID"];

私有动画

iphone种还有很多动画是苹果私有的,例如删除照片的动画等, 私有动画可以直接在animation.type中传入动画的字符串即可。动画有以下几种:

cube:像立方体一样翻转 suckEffect:渐渐缩小,与删除照片动画一样 oglFlip:上下旋转,当subTypefromLeft或者fromRight时,与UIViewAnimationTransitionFlipFromLeftUIViewAnimationTransitionFlipFromRight一样 rippleEffect:水波效果 pageCurl:与UIViewAnimationTransitionCurlUp一样 pageUnCurl:与UIViewAnimationTransitionCurlDown一样 cameraIrisHollowOpenFirst half of cameraIris. cameraIrisHollowCloseSecond half of cameraIris

以上所有动画效果的demo请见http://www.cocoachina.com/bbs/read.php?tid-11820.html

UIViewAnimationState描述:http://www.iphonedevwiki.net/index.php/UIViewAnimationState

同时,本人在使用UIView实现suckEffect缩小的效果过程中遇到一个问题(不知道如何定位),经过搜索终觅得解决方法,分享如下:

[UIView beginAnimations:@"suck" context:NULL]; [UIView setAnimationTransition:103 forView:self.view cache:YES]; [UIView setAnimationDuration:0.5f]; if (self.interfaceOrientation  == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {   [UIView setAnimationPosition:CGPointMake(44, 42)]; }else { [UIView setAnimationPosition:CGPointMake(320 , 42)]; } [UIView commitAnimations];

其中setAnimationPosition方法就是用于设置缩小点的位置的,此处虽然会报一个警告,但是结果还是正确的。

 

关于软键盘弹出时的上移

先设置textfielddelegate = self

 

- (void)textFieldDidBeginEditing:(UITextField *)textField 

{

//获取这个textfieldtableview中的第几行

//再更具第几行设置页面高度(暂时还没有找到很好的通用方法来改变高度,网上也有说textfield嵌套再tableview中时,是可以自动调整页面高度的,不知道怎么设置)(前些天找到了,要继承UItabviewController而不是uiviewcontroller)

UITableViewCell *cell = (UITableViewCell *)[textField superview] ;

    NSInteger idx = [[self.tbView indexPathForCell:cell] row];

NSLog([NSString stringWithFormat:@"index:%d",idx]); 

switch (idx) {

        case 3:

            [self.tbView setContentOffset:CGPointMake(0, 130) animated:YES];//上移 130

            break;

        case 4:

            [self.tbView setContentOffset:CGPointMake(0, 160) animated:YES];

            break;

        case 5:

            [self.tbView setContentOffset:CGPointMake(0, 170) animated:YES];

            break;

        default:

            [self.tbView setContentOffset:CGPointMake(0, 0) animated:YES];

            break;

    }

}

 ------动态设置cell 的高度 :-----------------------------------

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    NSString *cellText = @"xx";

    

    if([indexPath row]==2){

        cellText = companyModal.companyAddress;

    }

    else{

        cellText = @"XXX";

    }

    

    UIFont *cellFont = [UIFont fontWithName:@"Helvetica Neue" size: 19];

    CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);

    CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

    return labelSize.height + 20;

}

 

 ------手势滑动 :----------------------------------- 

 #define HORIZ_SWIPE_DRAG_MIN 12

#define VERT_SWIPE_DRAG_MAX 4

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = [touches anyObject];

    startTouchPosition = [touch locationInView:self.view];

    dirString = NULL;

    dirString_f = NULL;

}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = touches.anyObject;

    CGPoint currentTouchPosition = [touch locationInView:self.view];

    

    if(fabs(startTouchPosition.x - currentTouchPosition.x)>=HORIZ_SWIPE_DRAG_MIN&&fabs(startTouchPosition.y - currentTouchPosition.y)<=VERT_SWIPE_DRAG_MAX){

        

        if(startTouchPosition.x < currentTouchPosition.x){

            dirString = kCATransitionFromLeft;

            dirString_f = kCATransitionFromRight;

        }

        else{

            dirString = kCATransitionFromRight;

            dirString_f = kCATransitionFromLeft;

        }

    }

    else if(fabs(startTouchPosition.y - currentTouchPosition.y)>=HORIZ_SWIPE_DRAG_MIN&&fabs(startTouchPosition.x - currentTouchPosition.x)<=VERT_SWIPE_DRAG_MAX){

        

        if(startTouchPosition.y < currentTouchPosition.y){

            dirString = kCATransitionFromBottom;

            dirString_f = kCATransitionFromTop;

        }

        else{

            dirString = kCATransitionFromTop;

            dirString_f = kCATransitionFromBottom;

        }

    }

    else{

    }

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

    

    if(dirString == kCATransitionFromLeft){

        [self btnLoginPress:@""];

    }

    if(dirString_f){

    }

}

 ------plistReader.h :-----------------------------------

 #import <Foundation/Foundation.h>

@interface plistReader : NSObject{

}

+(NSString *)doRead:(NSString *)fileName index:(NSInteger)index;

+(void)doWrite:(NSString *)fileName arr:(NSMutableArray *)arr;

@end

------plistReader.m:-----------------------------------

------使用的时候加个 autorelease

#import "plistReader.h"

@implementation plistReader

+(NSString *)doRead:(NSString *)fileName index:(NSInteger)index{

    NSArray *storeFilePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentDirectory = [storeFilePath objectAtIndex:0];

    NSString *fullFileName = [[[NSString alloc]initWithFormat:@"%@.plist",fileName]autorelease];

    NSString *fileDirectory = [documentDirectory stringByAppendingPathComponent:fullFileName];

    NSString *rtnStr=nil;

    if([[NSFileManager defaultManager]fileExistsAtPath:fileDirectory]){

        NSMutableArray *array = [[[NSMutableArray alloc]initWithContentsOfFile:fileDirectory]autorelease];

        rtnStr = [[array objectAtIndex:index]copy];

    }

    return rtnStr;

}

+(void)doWrite:(NSString *)fileName arr:(NSMutableArray *)arr{

    //add to plist

    NSArray *storeFilePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = [storeFilePath objectAtIndex:0];

    NSString *fullFileName = [[[NSString alloc]initWithFormat:@"%@.plist",fileName]autorelease];

    NSString *fileDirectory = [documentsDirectory stringByAppendingPathComponent:fullFileName];

    

    [arr writeToFile:fileDirectory atomically:YES];

}

@end

 

 ------更具 section 和row查找cell---------------------------------

NSIndexPath *path=[NSIndexPath indexPathForRow:row inSection:section];

UITableViewCell * cell = [self.tbView cellForRowAtIndexPath:path];

 

---------cellForRowAtIndexPath  最基本写法---------------------------

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString * CityCellIdentifier = @"CityCellIdentifier";

    

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

    

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CityCellIdentifier] autorelease];  

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }

    return cell;

 

------------UIDatePicker 的使用-------------------------

UIDatePicker *datePickerView_end = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, 250, 200)];

datePickerView_end.datePickerMode = UIDatePickerModeDate;

  [datePickerView_Begin addTarget:self action:@selector(dateChangedBegin:) forControlEvents:UIControlEventValueChanged ];

-(void)dateChangedBegin:(id)sender{

    UIDatePicker *datePickerView_Begin = (UIDatePicker *)sender;

    NSLog(@"%d",datePickerView_Begin.tag);

    

    UIDatePicker* control = (UIDatePicker*)sender;

    NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];//实例化一个NSDateFormatter对象

    [dateFormat setDateFormat:@"yyyy-MM-dd"];//设定时间格式,这里可以设置成自己需要的格式

    NSString *strDate = [dateFormat stringFromDate:control.date];

    

    switch (datePickerView_Begin.tag) {

        case 101:

            [self SetCellTextInSection:0 row:1 tag:101 strValue:strDate];

            orderMealCondi.fromTime = strDate;

            break;

        case 102:

            [self SetCellTextInSection:0 row:1 tag:102 strValue:strDate];

            orderMealCondi.toTime = strDate;

            break;   

        default:

            break;

    }

    

    [dateFormat release];

}

--------自定义cell-----------------------------

OrderMealCell *myCell = (OrderMealCell *)[tableView dequeueReusableCellWithIdentifier:@"OrderMealCell"];

    if (myCell == nil) {

        NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"OrderMealCell" owner:self options:nil];

        myCell = [nib objectAtIndex:0];

        

        myCell.selectionStyle = UITableViewCellSelectionStyleNone;

    }

 

-------uitableview 移动--------------------------------

 [self.tbView setContentOffset:CGPointMake(0, 150) animated:YES];

 

你可能感兴趣的:(ios)