- 浏览: 90918 次
- 性别:
- 来自: 苏州
文章分类
- 全部博客 (52)
- tomcat启动报错 (0)
- 数据库 (1)
- linux (2)
- myeclipse工具 (3)
- ibatis (3)
- struts (1)
- spring (0)
- 数据加密 (1)
- java代码 (5)
- iphone (1)
- android (3)
- flex (5)
- JSP (1)
- 监听器 (1)
- struts2+ibatis+spring (1)
- myeclipse 8.6 装反编译 (1)
- 对界面的封装 (1)
- log4j (1)
- 主键生成机制 (1)
- jdk (2)
- 正责表达式 (1)
- mac 系统 (1)
- 单元测式 (1)
- PowerDesigner (1)
- jbpm5.2 (1)
- 枚举 (1)
- jquery (2)
- extjs (2)
- tomcat (1)
- jbpm (1)
- 开源 (1)
- maven (2)
- dwr (1)
- Web 前端 (1)
最新评论
-
18335864773:
推荐另一种方法。用pageoffice生成excel。不需要用 ...
java jxl类生成excel -
xwq1849:
太需要了!!感谢感谢~!~~~
flex4 下拉框可以多选 CheckBoxTreeComboBox -
wxhwdmxl:
恩,这个我用到了,解决了我的问题,谢谢
linux 操作系统安装JDK后报Usage: gij错的解决方案 -
Franciswmf:
你好,请问你的jbpm5项目研究透了吗?我正在研究jbpm5, ...
jbpm5.2学习------安装与配置 -
hotapple:
请教下,我想查询用户已提交的申请的处理状态,是否要直接去查询j ...
jbpm4.4+ssh配置
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];
NSLog(@"title is %@",a.title);
}
}
7.使用TableView
1)在程序中添加ViewController
2)打开此Controller的xib文件,拖一个TableView组件放在界面上,按下alt+2,按下datasource和delegate右面的圆圈,拖到files owner对象上
3)打开viewcontroller.h文件,声明一个NSMutableArray*listData;并添在花括号下面加@property (nonatomic,retain)NSArray*listData;
4)打开M文件,在@implementation TableViewController1下面添加@synthesize listData;
5)在viewdidload方法中添加
NSArray*array=[[NSArray alloc]initWithObjects:@"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] sortedArrayUsingSelector: @selector(compare:)]; 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;
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];
NSLog(@"title is %@",a.title);
}
}
7.使用TableView
1)在程序中添加ViewController
2)打开此Controller的xib文件,拖一个TableView组件放在界面上,按下alt+2,按下datasource和delegate右面的圆圈,拖到files owner对象上
3)打开viewcontroller.h文件,声明一个NSMutableArray*listData;并添在花括号下面加@property (nonatomic,retain)NSArray*listData;
4)打开M文件,在@implementation TableViewController1下面添加@synthesize listData;
5)在viewdidload方法中添加
NSArray*array=[[NSArray alloc]initWithObjects:@"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] sortedArrayUsingSelector: @selector(compare:)]; 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;
相关推荐
根据提供的文件信息,本文将对“iPhone开发实战”这一主题进行深入探讨,涵盖iPhone应用开发的基础概念、开发环境搭建、关键技术点以及实际案例分析等方面。 ### 一、iPhone开发概述 #### 1.1 iPhone应用开发简介 ...
#### 四、iPhone开发环境 - **Xcode IDE**:这是苹果官方提供的集成开发环境,支持iPhone OS的开发。它不仅提供了代码编辑、编译和调试的功能,还支持在实际设备或模拟器上运行和调试程序。 - **iPhone模拟器**:在...
### 最新iPhone应用程序开发全教程知识点总结 #### 一、教程基本信息 - **书名**:《最新 iPhone 应用程序开发全教程》 - **英文名称**:Beginning iPhone 3 Development Exploring the iPhone SDK - **作者**:...
### iPhone开发基础教程知识点概述 #### 一、iPhone开发概览 - **移动平台新纪元**:Apple公司的iPhone标志着移动平台的新纪元,凭借其卓越的硬件性能和优秀的用户体验,吸引了全球范围内的开发者和用户。 - **App ...
学习iPhone开发是一个系统而全面的过程,它涉及到编程基础、开发工具、框架掌握等多个方面。文章以《如何学好iPhone开发》为主题,详细阐述了学习iPhone游戏开发所需的基础知识、推荐的学习资源、开发工具的运用、...
总结来说,这个“iPhone开发资料整理”集合了iPhone应用开发的关键元素,包括Cocoa框架的理解、Dashcode的实践应用、Objective-C编程语言的学习,以及可能涵盖的设备特性和优化技巧。这些资源对于想要踏入iPhone开发...
总结来说,《iPhone开发揭秘》这本书通过介绍iPhone程序的基本框架、非游戏框架的开发流程、OpenFlow编程技术以及UIViewController和UIView的管理,为初学者提供了一条清晰的iOS应用开发入门之路。对于想要深入学习...
总结上述知识点,可以发现斯坦福大学的iPhone软件开发课程重点介绍了以下核心概念: 1. MVC设计模式的理论和应用。 2. 模型、视图和控制器三个组件的职责和交互方式。 3. 代理模式在控制器和视图间通信的作用和实现...
在"iPhone开发【十】多视图技术总结之二:Navigation"中,博主可能详细讲解了以下几点: 1. **Navigation Bar**:导航控制器顶部的导航栏,显示了当前视图的标题,并且可以包含左侧和右侧的Bar Button Items,用于...
总结,iPhone开发iOS7涉及的知识点繁多,从开发环境的配置,到编程语言的选择,再到新特性的应用,每一个环节都需要开发者深入理解并熟练掌握。只有这样,才能充分利用iOS7的优势,创造出功能丰富、用户体验优秀的...
### Cocos2d-iPhone开发教程相关知识点 #### 一、Cocos2d-iPhone简介与版权要求 **Cocos2d-iPhone**是一款专为iOS设备设计的2D游戏开发框架,它基于OpenGL ES图形渲染,并且拥有丰富的功能集,能够支持多种游戏...
### iPhone开发环境搭建详解 #### 一、概述 在当今移动互联网时代,iPhone应用程序的开发需求日益增长。为了能够高效地进行iOS应用开发工作,搭建一个完善的开发环境至关重要。本文将详细介绍如何通过虚拟机(VM)...
### iPhone开发指南(中文版) #### 一、引言与背景 随着移动互联网技术的飞速发展,智能手机已经成为人们生活中不可或缺的一部分。对于开发者而言,掌握iOS平台的应用开发技能显得尤为重要。苹果公司为了帮助广大...
根据提供的文件信息,“iPhone3开发基础教程(中文高清)第11章”,我们可以推断出这一章节的内容将涉及iPhone应用程序开发的基础知识。由于标题和描述重复,并且部分内容并不包含实际的教学内容,我们将基于标题和...
### Win搭建iPhone开发环境知识点详解 #### 一、概述 在Windows环境下搭建iPhone开发环境是一项技术挑战,因为官方推荐的开发环境是在Mac OS X上进行的。然而,通过使用虚拟化技术,例如VMware Workstation,可以在...