摘要: 之前写过类似的文章,这篇以做总结,希望能帮助刚上船的兄弟。^_^iPhone系统中的Objective-C的内存管理机制是比较灵活的,即可以拿来像C/C++一样用,也可以加个AutoreleasePool让它升级为半自动化的内存管理语言。当然,也不能拿JAVA虚拟机中的全自动化GC来比〜一,引用计数是实例对象的内存回收唯一参考引用计数(retainCount)是Objective-C管理对象引用的唯一依据。调用实例的release方法后,此属性减一,减到为零时对象的dealloc方法被自动调用,进行内存回收操作,也就是说我们永不该手动调用对象的dealloc方法。它的内存管理API老简单老简单 阅读全文
posted @ 2012-05-14 13:35 妙笔 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 1 //CustomNavigationBar.h 2 @interface UINavigationBar (UINavigationBarCategory) 3 UIImageView *backgroundView; 4 - (void)setBackgroundImage:(UIImage*)image; 5 - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index; 6 @end 阅读全文
posted @ 2012-05-14 11:48 妙笔 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 1 //隐藏的方法2 [self.navigationController setNavigationBarHidden:YES animated:YES];3 //防止view乱跳的方法4 self.wantsFullScreenLayout = YES; 阅读全文
posted @ 2012-05-14 11:47 妙笔 阅读(549) 评论(0) 推荐(0) 编辑
摘要: 1 //表格透明 2 // 3 [TableView setBackgroundColor:[UIColor grayColor]]; 4 5 //Cellu背景色设置 6 7 - (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath 8 9 {static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; 10 11 UITableViewCell *ce 阅读全文
posted @ 2012-05-14 11:47 妙笔 阅读(429) 评论(0) 推荐(0) 编辑
摘要: 通常使用的Navigation Item中有backBarButtonItem/leftBarButtonItem/rightBarButtonItem三个按键,其中backBarButtonItem为只读,不能修改,其他两个都可以自由修改.不但可以防止button,还可以用自定义的view来填充,比方说想在导航栏右侧防止两个按钮,如图所示代码如下: 1 UIView *rightBarView = [[UIView alloc]initWithFrame:CGRectMake(618, 0, 150, 44)]; 2 3 UIButton *editBtn = [UIButton but.. 阅读全文
posted @ 2012-05-14 11:46 妙笔 阅读(1240) 评论(0) 推荐(0) 编辑
摘要: 导航栏的按钮,右边的按钮是可以自己随意添加的。但左边的返回按钮怎么定制?正确的答案是重载UINavigationController类的pushViewController:animated方法。 1 #import @interface MyNavigationController: UINavigationController 2 3 { 4 5 } 6 7 @end 8 9 #import "MyNavigationController.h" 10 11 @implementation MyNavigationController 12 13 -(void)popse 阅读全文
posted @ 2012-05-14 11:45 妙笔 阅读(1409) 评论(0) 推荐(0) 编辑
摘要: 1 //CustomNavigationBar.h 2 @interface UINavigationBar (UINavigationBarCategory) 3 UIImageView *backgroundView; 4 - (void)setBackgroundImage:(UIImage*)image; 5 - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index; 6 @end 7 //CustomNavigationBar.m 8 @implementation UINavigationBar (UINaviga. 阅读全文
posted @ 2012-05-14 11:44 妙笔 阅读(362) 评论(0) 推荐(0) 编辑
摘要: 实现右边的书签按钮: 1 UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] 2 3 initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self 4 5 action:@selector(methodtocall:) ]; 6 7 self.navigationItem.rightBarButtonItem = anotherButton; [anotherButton release]; 8 9 //由于本地视图会retain它,所... 阅读全文
posted @ 2012-05-14 11:36 妙笔 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 第一种: 1 NSStringEncoding encoder = NSUTF8StringEncoding; 2 3 NSString *file = [NSString stringWithContentsOfFile:@"/Users/bjimac/Desktop/528.edl" usedEncoding:&encoder 4 5 error:nil]; 6 7 NSRange line; 8 9 line.location = 0;10 11 l... 阅读全文
posted @ 2012-05-14 11:35 妙笔 阅读(343) 评论(0) 推荐(0) 编辑
摘要: NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:filePath];[fileHandle seekToFileOffset:1000];NSData *data = [fileHandle readDataOfLength:2000]; 阅读全文
posted @ 2012-05-14 11:34 妙笔 阅读(386) 评论(0) 推荐(0) 编辑
摘要: 在网上查了下资料,有两种方法:方法一,利用Quartz本身的绘图方法: 1 - (void) drawText:(NSString *)text x:(float)x y:(float)y { 2 3 CGContextRef context = UIGraphicsGetCurrentContext(); 4 5 CGContextSelectFont(context, "Arial", 20, kCGEncodingMacRoman); 6 7 CGContextSetTextDrawingMode(context, kCGTextFill); 8 9 CGAffine 阅读全文
posted @ 2012-05-14 11:29 妙笔 阅读(3074) 评论(0) 推荐(0) 编辑
摘要: loadView 和 viewDidLoad 是 iPhone 开发中肯定要用到的两个方法。 他们都可以用来在视图载入的时候初始化一些内容。 但是他们有什么区别呢? viewDidLoad 方法只有当 view 从 nib 文件初始化的时候才被调用。viewDidLoad 用于初始化,加载时用到。 loadView 方法在控制器的 view 为 nil 的时候被调用。 此方法用于以编程的方式创建 view 的时候用到。loadView 是使用代码生成视图的时候,当视图第一次载入的时候调用的方法。用于使用(写)代码来实现控件。用于使用代码生成控件的函数。如:1 - ( void ) loadVi 阅读全文
posted @ 2012-05-14 11:26 妙笔 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 32位 64位char 1 1int 4 大多数4,少数8long 4 8float 4 4double 8 8指针 4 8 阅读全文
posted @ 2012-05-14 11:26 妙笔 阅读(1724) 评论(0) 推荐(0) 编辑
摘要: 这么细节的东西想来大家都不在意,平时也不会去关系,但是在面试时却常常被提到,所以了解viewController的生命周期还是很有必要的。由init、loadView、viewDidLoad、viewDidUnload、dealloc的关系说起init方法在init方法中实例化必要的对象(遵从LazyLoad思想)?init方法中初始化ViewController本身loadView方法当view需要被展示而它却是nil时,viewController会调用该方法。不要直接调用该方法。如果手工维护views,必须重载重写该方法如果使用IB维护views,必须不能重载重写该方法loadView和 阅读全文
posted @ 2012-05-14 11:25 妙笔 阅读(121) 评论(0) 推荐(0) 编辑
摘要: viewDidAppear、viewWillAppear in UINavigationController not be calledWhen you push or pop a view controller on/off a navigaction controller's stack, the usual viewWillAppear / viewDidappear methods aren't called. If you want to ensure they're always called, just add the UINavigationContro 阅读全文
posted @ 2012-05-14 11:24 妙笔 阅读(483) 评论(0) 推荐(0) 编辑
摘要: 每个ios开发者对loadView和viewDidLoad肯定都很熟悉,虽然这两个函数使用上真的是非常简单,但是和类似的initWithNibName/awakeFromNib/initWithCoder放在一起还是非常容易让人混淆的.大前提是UIViewController有一个UIView.同时,需要理清两个概念,一、实例化一个类. 二、创建一个类。在XCode中创建一个类和实例化一个类很容易区分,但是在IB(Interface Builder)中有时候就会迷糊.其实也很好区分,孤零零地创建了一个nib文件,没有和其他可被实例化的类有直接或间接关系的时候,这个类或这些类(一个nib文件俺也 阅读全文
posted @ 2012-05-14 11:23 妙笔 阅读(582) 评论(0) 推荐(0) 编辑
摘要: 方法一,使用一个UIImageView实例做子视图,并且放最后面Objective-c代码 1 - (void)setBackgroundImage { 2 NSLog(@"setting bg image"); 3 UIImageView *customBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.jpg"]]; 4 self.background = customBackground; 5 [customBackgrou... 阅读全文
posted @ 2012-05-14 11:21 妙笔 阅读(348) 评论(0) 推荐(0) 编辑
摘要: 详解iPhone下如何获取对象教程是本文要介绍的内容,主要是讲述iPhone下如何获取对象句柄和其父对象句柄,很详细的让我们去了解iphone中的对象,先来看详细内容。常规iPhone程序对象结构如下:对象个数对象类型1UIApplication 1UIApplicationDelegate/subclass 1,NUIViewController/subclass 1,NUIView/subclsss尽管有些书上说可以绕过UIViewController直接对UIView进行操作,但个人认为此层的作用用于管理视图和视图关系。下面分别对上述层次关系的对象类型进行学习。说明下,下面学习的东西仅和 阅读全文
posted @ 2012-05-14 11:19 妙笔 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 详解iPhone下如何获取对象教程是本文要介绍的内容,主要是讲述iPhone下如何获取对象句柄和其父对象句柄,很详细的让我们去了解iphone中的对象,先来看详细内容。常规iPhone程序对象结构如下:对象个数对象类型1UIApplication 1UIApplicationDelegate/subclass 1,NUIViewController/subclass 1,NUIView/subclsss尽管有些书上说可以绕过UIViewController直接对UIView进行操作,但个人认为此层的作用用于管理视图和视图关系。下面分别对上述层次关系的对象类型进行学习。说明下,下面学习的东西仅和 阅读全文
posted @ 2012-05-14 11:16 妙笔 阅读(178) 评论(0) 推荐(0) 编辑
摘要: NSString 转换成NSData 对象 NSData* xmlData = [@"testdata" dataUsingEncoding:NSUTF8StringEncoding]; NSData 转换成NSString对象 NSData * data; NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];NSData 转换成char*NSData *data;char *test=[data bytes];char* 转换成NSData对象byte* 阅读全文
posted @ 2012-05-14 11:12 妙笔 阅读(122) 评论(0) 推荐(0) 编辑