Iphone 開發筆記php
/////////////////////////////////////////////////////////////////html
// 基本框架api
/////////////////////////////////////////////////////////////////app
基本框架:框架
Library 一些幫助類iview
--UserLib 用戶自定義幫助類iphone
--Lib 特定功能的幫助類ide
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是一個Object(class爲AppDelegate)
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,如想跳轉,請用UINavigationController的push方法push一個新的UIViewController,或者使用UIViewController的presentModelViewController方法來彈出一個新的頁面,注意此頁面會遮住下面的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 Owner爲object , 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;//設置動畫的方向,有四種,分別爲kCATransitionFromRight、kCATransitionFromLeft、kCATransitionFromTop、kCATransitionFromBottom [self.view.layer addAnimation:animation forKey:@"animationID"];
私有動畫
iphone種還有不少動畫是蘋果私有的,例如刪除照片的動畫等, 私有動畫能夠直接在animation.type中傳入動畫的字符串便可。動畫有如下幾種:
cube:像立方體同樣翻轉 suckEffect:漸漸縮小,與刪除照片動畫同樣 oglFlip:上下旋轉,當subType爲fromLeft或者fromRight時,與UIViewAnimationTransitionFlipFromLeft和UIViewAnimationTransitionFlipFromRight同樣 rippleEffect:水波效果 pageCurl:與UIViewAnimationTransitionCurlUp同樣 pageUnCurl:與UIViewAnimationTransitionCurlDown同樣 cameraIrisHollowOpen:First half of cameraIris. cameraIrisHollowClose:Second 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方法就是用於設置縮小點的位置的,此處雖然會報一個警告,可是結果仍是正確的。
關於軟鍵盤彈出時的上移
先設置textfield的delegate = self
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
//獲取這個textfield在tableview中的第幾行
//再更具第幾行設置頁面高度(暫時尚未找到很好的通用方法來改變高度,網上也有說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;
------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];
}
------更具 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];