ipone 开发总结

1.创建第一个程序
1).创建项目 ,然后添加一个新的viewcontroller文件,这时会生成.h .m .xib文件 ,在项目 名称appdeletegate.h中添加
UINavigationController *mainNavigation;
2).在.m文件中application方法中添加
//别忘记 导入包
mainNavigation=[[UINavigationController alloc]init ];

mainNavigation=[[UINavigationController alloc]init ];
MainViewController*mainView=[[MainViewController alloc]init ];
mainView.title=@"主页面";
//将viewcontroller添加到主导航器中
[mainNavigation pushViewController:mainView animated:NO];
//将mainNavigation作为程序的导航器
[self.window addSubview:mainNavigation.view];
//将mainview释放
[mainView release];

3).接下来要定义事件关联
在mainviewcontroller.h文件中声明变量,是为了与界面中的两个组件关联

IBOutlet UILabel*label;
IBOutlet UIButton *button;
4).声明方法
-(IBAction)clickBtn:(id)sender;
5).在.m文件中实现这个方法
-(IBAction)clickBtn:(id)sender{
NSLog(@"click.....");
label.text=@"Hello....";
}
6).打开IB,点击”file owner”图标,将里面的属性拖动到对应的组件上,将方法拖到按钮上,这时会显示所有事件,选中一个


2.页面跳转 与传值
1).创建一个viewcontroller,在mainview中导入此文件的接口
声明实例,如下:
CarNoViewController *carnoView=[[CarNoViewController alloc]init ];
carnoView.title=@"车牌号";
carnoView.userName=@"bushi";
[self.navigationController pushViewController:carnoView animated:YES];
[carnoView release];
2)在第二个viewcontroller中的.h文件中声明一个属性,如下
int age;
NSString *userName;
//注意,上面是在{}中,下面是在外面
@property (nonatomic,retain)NSString *userName;
@property int age;
在.m文件中添加
//@implementation CarNoViewController
@synthesize age;
@synthesize userName;

在第一个viewcontroller中就可以设置此实例中的此属性值了

1.通过拖动OBJECT添加类类:
在 XIB界面添加OBJECT对象,在属 性中输入类名,接着点击类名后面的一个灰色箭头,会显示此类的另一些属性
在IBOUTLET和IBACTION中输入属 性和方法
双 击刚才添加的OBJECT,会显示新添加的属性和方法,将属性和方法拖动到对应的组件中
2。为为程序添加图标图标
将一个图片文件拖到RESOURCE文件夹中,打开PLIST文件,修改里面的ICONFILE值为@"icon.png"即可
3.定义数组
NSArray *userNameArray=[NSArray arrayWithObjects:@"Bushi",@"Aobama",@"Kelindun",nil];
//取数组中某个数据
label1.text=[NSString stringWithFormat:@"%@",[userNameArray objectAtIndex:0]];

4.titleView添加按钮
在要添加的viewcontroller中的viewdidload添加如下代码

UIView *titleView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 20)];
[titleView setBackgroundColor:[UIColor clearColor]];


UIButton *titleBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[titleBtn setFrame:CGRectMake(0, 0, 40, 20)];
[titleBtn addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
[titleBtn setTitle:@"Help" forState:UIControlStateNormal];
[titleBtn setFont:[UIFont systemFontOfSize:8]];
[titleView addSubview:titleBtn];

self.navigationItem.titleView=titleView;
[titleView release];

5.TableView添加数据
1)。在H文件中声明
NSArray *m_data;
并添加
@property (nonatomic,retain)NSArray*m_data;
2)。在M文件IMPLEMENTION下面添加
@synthesize m_data;
3)在VIEWDIDLOAD中添加如下代码
NSArray *arr=[[NSArray alloc]initWithObjects:@"Jinan",@"Beijing",@"上海",nil];
self.m_data=arr;
[arr release];
4)继续在M文件下面添加如下方法
-(NSInteger)tableView:(UITableView*)tableView
numberOfRowsInSection:(NSInteger)section{
return [m_data count];

}
-(UITableViewCell*)tableView:(UITableView*)tableView
cellForRowAtIndexPath:(NSIndexPath*)
indexPath{
static NSString *TableViewDynamicLoadIDentifier=
@"TableViewDynamicLoadIdentifier";
UITableViewCell *pCell=[tableView dequeueReusableCellWithIdentifier:TableViewDynamicLoadIDentifier];
if(pCell==nil){
pCell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableViewDynamicLoadIDentifier]autorelease];

}
NSInteger nRow=[indexPath row];
pCell.textLabel.text=[m_data objectAtIndex:nRow];
return pCell;
}


-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
NSUInteger row=indexPath.row;
NSString *s=[NSString stringWithFormat:@"%d",row];
NSLog(s);
}

//设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 65.0f;
}


6,CoreData 核心数据
添加开发支持
1)点击FRAMEWORKS目录,右键添加FRAMWORK中的COREDATA
2)双击生成的XCDATAMODEL文件
3)添加对象和属性,建立关系
4)FILE-NEW FILE-COCOATOUCHCLASS-MANAGEDOBJECTCLASS
在H文件中声明
NSManagedObjectContext * manageObjectCon;
@property (nonatomic,retain)NSManagedObjectContext *manageObjectCon;

在M文件中

@synthesize manageObjectCon;

-(NSManagedObjectContext *)manageObjectCon{
if(manageObjectCon==nil){
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath=([paths count]>0) ? [paths objectAtIndex:0]:nil;
NSURL*url=[NSURL fileURLWithPath:[basePath stringByAppendingPathComponent:@"books.sqlite"]];
NSError*err;
NSPersistentStoreCoordinator*persistentStoreCoordinator=
[[NSPersistentStoreCoordinator alloc]initWithManagedObjectModel:[NSManagedObjectModel mergedModelFromBundles:nil]];
if(![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:nil error:&err])
{
NSLog(@"Failed to add persistent store with type to persistent store coordinator");
}
manageObjectCon=[[NSManagedObjectContext alloc]init];
[manageObjectCon setPersistentStoreCoordinator:persistentStoreCoordinator];

}
return manageObjectCon;
}

-(void)demo{
//save two book and author
Book *b1=(Book *)[NSEntityDescription insertNewObjectForEntityForName:@"Book" inManagedObjectContext:self.manageObjectCon];
Book *b2=(Book *)[NSEntityDescription insertNewObjectForEntityForName:@"Book" inManagedObjectContext:self.manageObjectCon];

Author *a1=(Author*)[NSEntityDescription insertNewObjectForEntityForName:@"Author" inManagedObjectContext:self.manageObjectCon];
Author *a2=(Author*)[NSEntityDescription insertNewObjectForEntityForName:@"Author" inManagedObjectContext:self.manageObjectCon];

b1.name=@"Android Development";
a1.name=@"LLG";
b2.name=@"Iphone Development";
a2.name=@"LuLiGuo";
[a1 addWriteRelationshipObject:b1];
[a2 addWriteRelationshipObject:b2];

// read data from coredata
NSArray*booksAuthor2Wrote=[a2.writeRelationship allObjects];
for(int i=0;i<[booksAuthor2Wrote count];i++){
Book *tempBook=(Book *)[booksAuthor2Wrote objectAtIndex:i];
NSLog(@"book %@ wrote include:%@",a2.name,tempBook.name);
}


}
在应用程序的加载中添加
[self manageObjectCon];
[self demo];

添加记录
Article *article1=(Article *)[NSEntityDescription insertNewObjectForEntityForName:@"Article" inManagedObjectContext:manageObjectCon];
article1.title=@"Title1";

查询某个对象所有记录
-(IBAction)queryData:(id)sender{

NSError *error;
NSLog(@"query...");
NSFetchRequest*fetchRequest=[[NSFetchRequest alloc]init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Article" inManagedObjectContext:manageObjectCon]];
NSSortDescriptor*sortDescriptor=[[NSSortDescriptor alloc]initWithKey:@"title" ascending:YES selector:nil];
NSArray*descriptors=[NSArray arrayWithObject:sortDescriptor];
[fetchRequest setSortDescriptors:descriptors];
NSPredicate*pred=[NSPredicate predicateWithFormat:@"(title=%@)",@"Title1"];//按条件查询
[fetchRequest setPredicate:pred];
NSArray*objects=[manageObjectCon executeFetchRequest:fetchRequest error:&error];
int c=[objects count];
NSLog(@"count is %d",c);
for (int i=0; i<[objects count]; i++) {
Article*a=(Article*)[objects objectAtIndex:i][NSArray alloc]nitWithObjects:@"Hello",@"HAHA",@"Heihei",nil];
self.listData=array;
[array release];
6).添加如下方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [self.listData count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text=[listData objectAtIndex:indexPath.row];
cell.detailTextLabel.text=@"Detail..";
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
// Configure the cell...
return cell;
}
7)在viewDidUnload中添加self.listData=nil;
8)在dealloc方法中添加[listData release];
9)最后就是把viewcontroller显示在界面上了
sysNavigation=[[UINavigationController alloc]init];
TableViewController1 *tvc=[[TableViewController1 alloc]init];
tvc.title=@"TABLEVIEW";
[sysNavigation pushViewController:tvc animated:NO];
[window addSubview:sysNavigation.view];



8.如何使用sqlite
1)点击项目中的frameworks,鼠标右键,添加libssqlite3.dylib
2)在.h文件中导入包 #import "sqlite3.h"
3)定义sqlite3 *database_;
BOOL *bFirstCreate;
4)在.m文件中导入包#import "sqlite3.h"
5)定义如下方法

-(BOOL)open{
NSArray*paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString*documentsDirectory=[paths objectAtIndex:0];
NSString*path=[documentsDirectory stringByAppendingPathComponent:@"mydb.sql"];
NSFileManager*fileManager=[NSFileManager defaultManager];
BOOL find=[fileManager fileExistsAtPath:path];
//找到数据库文件MYDB。SQL
if(find){
NSLog(@"数据库文件已经找到 ");
if(sqlite3_open([path UTF8String], &database_)!=SQLITE_OK){
sqlite3_close(database_);
NSLog(@"打开数据库文件错误 。。。。");
return NO;
}
return YES;
}
if(sqlite3_open([path UTF8String], &database_)==SQLITE_OK){
bFirstCreate=YES;
[self createChannelsTable:database_];
return YES;
}else{

sqlite3_close(database_);
NSLog(@"打开数据库文件出错");
return NO;
}
return NO;

}

//创建文件表
-(BOOL)createArticleTable:(sqlite3*)db{
NSLog(@"创 建文件表");
char*errorMsg;
NSString*createSQL=@"create table if not exists Article(aid integer primary key,title text,content text);";
if(sqlite3_exec(database_, [createSQL UTF8String], NULL, NULL, &errorMsg)!=SQLITE_OK)
{
sqlite3_close(database_);
NSAssert1(0,@"Error creating table :%s",errorMsg);
}
return YES;

}

6)在应用程序启动的方法中添加
[self open];
[self createArticleTable:database_];
7)添加记录的方法
-(IBAction)insertData:(id)sender{
NSLog(@"start insertdata().....");
char *insert="insert or replace into Article(aid,title,content) values(?,?,?);";
sqlite3_stmt *stmt;
if(sqlite3_prepare_v2(database_, insert, -1, &stmt, nil)==SQLITE_OK){
//sqlite3_bind_int(stmt, 1, 1);
sqlite3_bind_text(stmt, 2, [@"title1" UTF8String], -1, NULL);
sqlite3_bind_text(stmt, 3, [@"content1" UTF8String], -1, NULL);
}
if (sqlite3_step(stmt)!=SQLITE_DONE) {
NSLog(@"error insert data....");
}
sqlite3_finalize(stmt);
}

-(IBAction)deleteData:(id)sender{
NSLog(@"start deletedata().....");
char *insert="delete from Article where title=?;";
sqlite3_stmt *stmt;
if(sqlite3_prepare_v2(database_, insert, -1, &stmt, nil)==SQLITE_OK){
sqlite3_bind_text(stmt, 1, [@"title1" UTF8String], -1, NULL);

}
if (sqlite3_step(stmt)!=SQLITE_DONE) {
NSLog(@"error delete data....");
}
sqlite3_finalize(stmt);

}
-(IBAction)updateData:(id)sender{
}
-(IBAction)queryData:(id)sender{
NSLog(@"start querydata().....");
NSString *query=@"SELECT TITLE,CONTENT FROM ARTICLE";
sqlite3_stmt*stmt;
if(sqlite3_prepare_v2(database_, [query UTF8String], -1, &stmt, nil)==SQLITE_OK){
while (sqlite3_step(stmt)==SQLITE_ROW) {
//如果某列是int则为 int i=sqlite3_column_int();
char *t=(char *)sqlite3_column_text(stmt, 0);
char *c=(char *)sqlite3_column_text(stmt, 1);

NSString *title=[[NSString alloc]initWithUTF8String:t];
NSString *content=[[NSString alloc]initWithUTF8String:c];
NSLog(@"title is %@",title);
}

}else {
NSLog(@"LLG:Connect to database has error....");
}


}


9.拖动效果 左右拖动 轻扫
在M文件中添加如下方法

#pragma mark label
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
isAdd=1;
NSLog([@"touchesBegan....." stringByAppendingFormat:@"%d",isAdd]);
UITouch*touch=[touches anyObject];
gestureStartPoint=[touch locationInView:self.view];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch*touch=[touches anyObject];
CGPoint currentPosition=[touch locationInView:self.view];
CGFloat deltax=fabsf(gestureStartPoint.x-currentPosition.x);
CGFloat deltay=fabsf(gestureStartPoint.y-currentPosition.y);

if (deltax>=kMiniMMGestureLength&&deltay<=kMaximmVariance) {
if (gestureStartPoint.x>currentPosition.x) {
NSLog(@"Horizontal left swipe detected");

}}


}

10.自定义tableViewCell 样式

将一个tableview拖到界面上,alt+2 关连数据库和维拖
.h文件中
#import <UIKit/UIKit.h>
#define kNameValueTag 1
#define kColorValueTag 2

@interface MainViewController : UIViewController
<UITableViewDataSource,UITableViewDelegate>
{

NSArray *computers;
}

@property (nonatomic,retain) NSArray*computers;
@end


.m文件中

@synthesize computers;

- (void)viewDidLoad {
NSDictionary*row1=[[NSDictionary alloc]initWithObjectsAndKeys:@"MacBook",@"Name",@"White",@"Color" ,nil];
NSDictionary*row2=[[NSDictionary alloc]initWithObjectsAndKeys:@"MacBook Pro",@"Name",@"Silver",@"Color" ,nil];
NSDictionary*row3=[[NSDictionary alloc]initWithObjectsAndKeys:@"iMac",@"Name",@"Silver",@"Color" ,nil];
NSDictionary*row4=[[NSDictionary alloc]initWithObjectsAndKeys:@"MacBook",@"Name",@"White",@"Color" ,nil];

NSArray*array=[[NSArray alloc]initWithObjects:row1,row2,row3,row4,nil ];
self.computers=array;
[row1 release];
[row2 release];
[row3 release];
[row4 release];
[array release];
[super viewDidLoad];
}


-(NSInteger)tableView:(UITableView*)tableView
numberOfRowsInSection:(NSInteger)section{
return [computers count];

}
-(UITableViewCell*)tableView:(UITableView*)tableView
cellForRowAtIndexPath:(NSIndexPath*)
indexPath{
static NSString*CellTableIdentifier=@"CellTableIdentifier";

UITableViewCell *pCell=[tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
if(pCell==nil){
pCell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellTableIdentifier]autorelease];
CGRect nameLabelRect=CGRectMake(0, 5, 70, 15);
UILabel*nameLabel=[[UILabel alloc]initWithFrame:nameLabelRect ];
nameLabel.textAlignment=UITextAlignmentRight;
nameLabel.text=@"Name:";
nameLabel.font=[UIFont boldSystemFontOfSize:12];
[pCell.contentView addSubview:nameLabel];
[nameLabel release];

CGRect colorLabelRect=CGRectMake(0, 26, 70, 15);
UILabel *colorLabel=[[UILabel alloc]initWithFrame:colorLabelRect ];
colorLabel.textAlignment=UITextAlignmentRight;
colorLabel.text=@"Color:";
colorLabel.font=[UIFont boldSystemFontOfSize:12];
[pCell.contentView addSubview:colorLabel];
[colorLabel release];

CGRect nameValueRect=CGRectMake(80, 5, 200, 15);
UILabel *nameValue=[[UILabel alloc]initWithFrame:nameValueRect ];
nameValue.tag=kNameValueTag;
[pCell.contentView addSubview:nameValue];
[nameValue release];

CGRect colorValueRect=CGRectMake(80, 25, 200, 15);
UILabel *colorValue=[[UILabel alloc]initWithFrame:colorValueRect ];

colorValue.tag=kColorValueTag;
[pCell.contentView addSubview:colorValue];
[colorValue release];

}
NSInteger row=[indexPath row];
NSDictionary *rowData=[self.computers objectAtIndex:row];
UILabel*name=(UILabel*)[pCell.contentView viewWithTag:kNameValueTag];
name.text=[rowData objectForKey:@"Name"];
UILabel*color=(UILabel*)[pCell.contentView viewWithTag:kColorValueTag];
color.text=[rowData objectForKey:@"Color"];
return pCell;
}

16.TableView 分组表
1).在resources文件夹下创建plist文件
2).拖一个tableview到界面,并设置datasource和delegate
3).更改tableview的样式style为 Grouped
4).在.h文件中声明
@interface SectionsViewController : UIViewController
 <UITableViewDataSource, UITableViewDelegate>
 {
  NSDictionary *names;
  NSArray     *keys;
 }
 @property (nonatomic, retain) NSDictionary *names;
 @property (nonatomic, retain) NSArray *keys;
5)在.m文件中
@synthesize names;
@synthesize keys;
6).在viewdidload中
//获取属性列表的路径   sortednames.plist
    NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames"
                                                     ofType:@"plist"];
 
//实例化一个字典
   
NSDictionary *dict = [[NSDictionary alloc]
                          initWithContentsOfFile:path];
   
self.names = dict;
    [dict release];
   
   
NSArray *array = [[names allKeys][NSArray alloc]initWithObjects:@"One",@"Two",@"Three",nil ];
NSArray*arr2=[[NSArray alloc]initWithObjects:@"One1",@"Two1",@"Three1",nil ];

NSDictionary*dict=[[NSDictionary alloc]initWithObjectsAndKeys:arr1,@"Title1",arr2,@"Title2",nil];

*/


7).在最后添加如下代码
#pragma mark -
#pragma mark Table View Data Source Methods
//获取分区的数量 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [keys count];
}
//获取分区里的行的数量
//section为其中的一个分区
- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
    NSString *key = [keys objectAtIndex:section];
    NSArray *nameSection = [names objectForKey:key];
    return [nameSection count];
}

//行的创建
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 //获取第几分区
    NSUInteger section = [indexPath section];
 //获取行
    NSUInteger row = [indexPath row];
   
    NSString *key = [keys objectAtIndex:section];
    NSArray *nameSection = [names objectForKey:key];
   
    static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
   
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                             SectionsTableIdentifier ];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier: SectionsTableIdentifier ] autorelease];
    }
   
    cell.textLabel.text = [nameSection objectAtIndex:row];
    return cell;
}
//为每个分区指定一个名称  现在的名称为key的值
- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section
{
    NSString *key = [keys objectAtIndex:section];
    return key;
}
//添加索引,索引的值为右侧的a--z
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return keys;
}

15.自定义TableViewCell
-(void)makeSubCell:(UITableViewCell *)aCell withTitle:(NSString *)title
value:(NSString *)value
{
CGRect tRect = CGRectMake(20,5, 50, 40);
id lbl = [[UILabel alloc] initWithFrame:tRect]; //此处使用id定义任何控件对象
[lbl setText:title];
[lbl setBackgroundColor:[UIColor clearColor]];

CGRect tEdtRect = CGRectMake(50,15, 320, 40);
id edtPassword = [[UILabel alloc] initWithFrame:tEdtRect];
[edtPassword setText:value];
[edtPassword setBackgroundColor:[UIColor clearColor]];
//[edtPassword setKeyboardType:UIKeyboardTypeNumberPad];
// [edtPassword setSecureTextEntry:YES];
CGRect iEdtRect = CGRectMake(50,15, 320, 40);
id ima = [[UIImageView alloc] initWithFrame:tEdtRect];


[aCell addSubview:lbl];
[aCell addSubview:edtPassword];
[aCell addSubview:ima];


//release someone
[lbl release];
[edtPassword release];

}


//函数二 表格控制函数
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"Simple";

UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SimpleTableIdentifier] autorelease];
NSUInteger row = [indexPath row];

switch (row) {
case 0:
[self makeSubCell:cell withTitle:@"A:" value:@"password"];
break;
case 1:
[self makeSubCell:cell withTitle:@"B:" value:@"new password"];
break;
case 2:
[self makeSubCell:cell withTitle:@"C:" value:@"confirm password"];
break;
case 3:
[self makeSubCell:cell withTitle:@"D:" value:@"confirm password"];
break;
}
if (cell == nil)
{
NSLog(@"cell = nil");
}else
{
NSLog(@"cell <> nil");
}
return cell;
}

17.解析xml libxml 2.2
1.添加 libxml2 frameworks
   xcode中右击 "FrameWorks" ->Add->Add existing FWrameorks ,选择 "DyLibs",在其中选取libxml2 的dylib包,我选取的是 libxml2.2.7.3.dylib ,Add 即可
 
2.设置"Header Search Paths"
  在xcode中project->edit project settings->build 找到 "search paths",然后在Header Search Paths中添加
Xml代码  HYPERLINK "javascript:void()"
/usr/include/libxml2  
 这样添加也可以:
Xml代码  HYPERLINK "javascript:void()"
/Developer/Platforms/iPhoneOS.platform/Develope/SDKs/iPhoneOS4.0.sdk/usr/include/libxml2  

18.多线程
// NSThread*t1=[[NSThread alloc]initWithTarget:self selector:@selector(jishi) object:nil ];
// [t1 start];
19记时器
NSTimer*myTimer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(jishi) userInfo:nil repeats:YES];


20.数据存储 NSUserDefaults

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[NSString stringWithFormat:@"%d",time] forKey:@"ESS_STUDY_TIME"];
[defaults synchronize];

//NSString *testStr = [defaults objectForKey:@"myTest"];
//NSLog(@"testStr is: %@",testStr);

21.CoreText 排版 文字排版 文字样式 文字颜色 文字格式 下划线 字体

//创建要输出的字符串
NSString*longText=@"dsafdsafdsafdsfdsaf dsfdsf";
//创建AttributeString
NSMutableAttributedString*string=[[NSMutableAttributedString alloc]initWithString:longText ];
//创建字体以及字体大小

CTFontRef helvetica=CTFontCreateWithName(CFSTR("Helvetica"),14.0,NULL);
CTFontRef helveticaBold=CTFontCreateWithName(CFSTR("Helvetica-Bold"),14.0,NULL);
//添加字体目标字符串从下标0开始到字符串结尾
[string addAttribute:(id)kCTFontAttributeName value:(id)helvetica range:NSMakeRange(0, [string length])];
//添加字体目标字符串从下标0开始,截止到4个单位的长度
[string addAttribute:(id)kCTFontAttributeName value:(id)helveticaBold range:NSMakeRange(0, 4)];
//添加字体目标字符串从下标6开始,截止到5个单位长度
[string addAttribute:(id)kCTFontAttributeName value:(id)helveticaBold range:NSMakeRange(6, 5)];
//添加颜色,目标字符串从下标0开始,截止到4个单位长度
[string addAttribute:(id)kCTForegroundColorAttributeName value:(id)[UIColor blueColor].CGColor range:NSMakeRange(0, 4)];

//下划线功能
[NSDictionary dictionaryWithObjectsAndKeys:(id)sysUIFont,(id)kCTFontAttributeName,color,(id)kCTForegroundColorAttributeName,underline,(id)kCTUnderlineStyleAttributeName,nil];

22.右侧按钮

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]
initWithTitle:@"查看正确答案"
style:UIBarButtonItemStylePlain
target:self
action:@selecto
    self.keys = array;
/*
//或者在自定义内容
NSArray*arr1=[[NSArray alloc]initWithObjects:@"One",@"Two",@"Three",nil ];
NSArray*arr2=[[NSArray alloc]initWithObjects:@"One1",@"Two1",@"Three1",nil ];

NSDictionary*dict=[[NSDictionary alloc]initWithObjectsAndKeys:arr1,@"Title1",arr2,@"Title2",nil];

*/


7).在最后添加如下代码
#pragma mark -
#pragma mark Table View Data Source Methods
//获取分区的数量 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [keys count];
}
//获取分区里的行的数量
//section为其中的一个分区
- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
    NSString *key = [keys objectAtIndex:section];
    NSArray *nameSection = [names objectForKey:key];
    return [nameSection count];
}

//行的创建
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 //获取第几分区
    NSUInteger section = [indexPath section];
 //获取行
    NSUInteger row = [indexPath row];
   
    NSString *key = [keys objectAtIndex:section];
    NSArray *nameSection = [names objectForKey:key];
   
    static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
   
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                             SectionsTableIdentifier ];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier: SectionsTableIdentifier ] autorelease];
    }
   
    cell.textLabel.text = [nameSection objectAtIndex:row];
    return cell;
}
//为每个分区指定一个名称  现在的名称为key的值
- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section
{
    NSString *key = [keys objectAtIndex:section];
    return key;
}
//添加索引,索引的值为右侧的a--z
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return keys;
}

15.自定义TableViewCell
-(void)makeSubCell:(UITableViewCell *)aCell withTitle:(NSString *)title
value:(NSString *)value
{
CGRect tRect = CGRectMake(20,5, 50, 40);
id lbl = [[UILabel alloc] initWithFrame:tRect]; //此处使用id定义任何控件对象
[lbl setText:title];
[lbl setBackgroundColor:[UIColor clearColor]];

CGRect tEdtRect = CGRectMake(50,15, 320, 40);
id edtPassword = [[UILabel alloc] initWithFrame:tEdtRect];
[edtPassword setText:value];
[edtPassword setBackgroundColor:[UIColor clearColor]];
//[edtPassword setKeyboardType:UIKeyboardTypeNumberPad];
// [edtPassword setSecureTextEntry:YES];
CGRect iEdtRect = CGRectMake(50,15, 320, 40);
id ima = [[UIImageView alloc] initWithFrame:tEdtRect];


[aCell addSubview:lbl];
[aCell addSubview:edtPassword];
[aCell addSubview:ima];


//release someone
[lbl release];
[edtPassword release];

}


//函数二 表格控制函数
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @"Simple";

UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SimpleTableIdentifier] autorelease];
NSUInteger row = [indexPath row];

switch (row) {
case 0:
[self makeSubCell:cell withTitle:@"A:" value:@"password"];
break;
case 1:
[self makeSubCell:cell withTitle:@"B:" value:@"new password"];
break;
case 2:
[self makeSubCell:cell withTitle:@"C:" value:@"confirm password"];
break;
case 3:
[self makeSubCell:cell withTitle:@"D:" value:@"confirm password"];
break;
}
if (cell == nil)
{
NSLog(@"cell = nil");
}else
{
NSLog(@"cell <> nil");
}
return cell;
}

17.解析xml libxml 2.2
1.添加 libxml2 frameworks
   xcode中右击 "FrameWorks" ->Add->Add existing FWrameorks ,选择 "DyLibs",在其中选取libxml2 的dylib包,我选取的是 libxml2.2.7.3.dylib ,Add 即可
 
2.设置"Header Search Paths"
  在xcode中project->edit project settings->build 找到 "search paths",然后在Header Search Paths中添加
Xml代码  HYPERLINK "javascript:void()"
/usr/include/libxml2  
 这样添加也可以:
Xml代码  HYPERLINK "javascript:void()"
/Developer/Platforms/iPhoneOS.platform/Develope/SDKs/iPhoneOS4.0.sdk/usr/include/libxml2  

18.多线程
// NSThread*t1=[[NSThread alloc]initWithTarget:self selector:@selector(jishi) object:nil ];
// [t1 start];
19记时器
NSTimer*myTimer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(jishi) userInfo:nil repeats:YES];


20.数据存储 NSUserDefaults

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[NSString stringWithFormat:@"%d",time] forKey:@"ESS_STUDY_TIME"];
[defaults synchronize];

//NSString *testStr = [defaults objectForKey:@"myTest"];
//NSLog(@"testStr is: %@",testStr);

21.CoreText 排版 文字排版 文字样式 文字颜色 文字格式 下划线 字体

//创建要输出的字符串
NSString*longText=@"dsafdsafdsafdsfdsaf dsfdsf";
//创建AttributeString
NSMutableAttributedString*string=[[NSMutableAttributedString alloc]initWithString:longText ];
//创建字体以及字体大小

CTFontRef helvetica=CTFontCreateWithName(CFSTR("Helvetica"),14.0,NULL);
CTFontRef helveticaBold=CTFontCreateWithName(CFSTR("Helvetica-Bold"),14.0,NULL);
//添加字体目标字符串从下标0开始到字符串结尾
[string addAttribute:(id)kCTFontAttributeName value:(id)helvetica range:NSMakeRange(0, [string length])];
//添加字体目标字符串从下标0开始,截止到4个单位的长度
[string addAttribute:(id)kCTFontAttributeName value:(id)helveticaBold range:NSMakeRange(0, 4)];
//添加字体目标字符串从下标6开始,截止到5个单位长度
[string addAttribute:(id)kCTFontAttributeName value:(id)helveticaBold range:NSMakeRange(6, 5)];
//添加颜色,目标字符串从下标0开始,截止到4个单位长度
[string addAttribute:(id)kCTForegroundColorAttributeName value:(id)[UIColor blueColor].CGColor range:NSMakeRange(0, 4)];

//下划线功能
[NSDictionary dictionaryWithObjectsAndKeys:(id)sysUIFont,(id)kCTFontAttributeName,color,(id)kCTForegroundColorAttributeName,underline,(id)kCTUnderlineStyleAttributeName,nil];

22.右侧按钮

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]
initWithTitle:@"查看正确答案"
style:UIBarButtonItemStylePlain
target:self
action:@selector(seeAnswer)];
self.navigationItem.rightBarButtonItem = rightButton;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值