contentsize和contentoffset 还有contentbox shadow insett有什么区别

苹果开发重要语法知识 | iOS开发讨论区 - CocoaChina 开发讨论区 - Powered by PHPWind
查看完整版本: [--
&Pages: ( 8 total )
苹果开发重要语法知识
NSDictionary和NSMutableDictionary字典就是关键字及其定义(描述)的集合。Cocoa中的实现字典的集合NSDictionary在给定的关键字(通常是一个NSString)下存储一个数值(可以是任何类型的对象)。然后你就可以用这个关键字来查找相应的数值。不同于数组,字典(也被称为散列表或关联数组)使用的是键查询的优化存储方式。它可以立即找出要查询的数据,而不需要遍历整个数组进行查找。可使用dictionaryWithObjectsAndKeys来创建字典查询字典的值:objectForKeyNSMutableDictionary的dictionary方法可以创建一个可变字典,也可以使用dictionaryWithCapaticy:。使用 setObject:forkey: 方法添加字典元素,如果关键字已存在,则用新植替换旧值。类似的,NSMutableDictionary类允许随意添加或删除字典元素。添加元素:setObject:forkey:删除元素:removeObjectForKey:示例字典(NSDictionary,NSMutableDictionary)操作4 * Elf Sundae  10/22/2010#import &Foundation/Foundation.h&8 #import &MyClass.h&9 10 intmain (intargc, const char *argv[]) { NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init]; //创建字典:dictionaryWithObjectsAndKeys:14    MyClass *my1 =[MyClass new];   MyClass *my2 =[MyClass new];  MyClass *my3 =[MyClass new];  MyClass *my4 =[MyClass new];  NSDictionary *myClassD20 myClassDict =[NSDictionary dictionaryWithObjectsAndKeys:21 my1, @&my1&,22 my2, @&my2&,23 my3, @&my3&,24 my4, @&my4&, nil]; //获取值 objectForKey26    MyClass *sub =[myClassDict objectForKey: @&my3&];  if(sub ==nil) {  exit(1);  }30 [sub setFirstName:@&Elf&];31 [sub setLastName:@&Sundae&];32 33 NSLog(@&修改数据: %@&,sub);34 35  //遍历字典36 NSLog(@&***遍历字典myClassDict如下:&);37  for(id key inmyClassDict)38 {39 NSLog(@&key: %@ ,value: %@&,key,[myClassDict objectForKey:key]);40 }41 NSLog(@&***遍历字典myClassDict结束。&);42 43  //MARK: ***  添加新元素  ***   44  //NSDictionary无法添加或删除元素,可以使用NSMutableDictionary.45 NSMutableDictionary *myNewDict =[NSMutableDictionary dictionary];46  //将原有字典添加到新字典的一对元素47  //[myNewDict setObject:myClassDic forKey:@&旧的不可变字典myClassDic&];48 49  //遍历添加已有数据(原字典)50  for(id key inmyClassDict)51 {52 [myNewDict setObject: [myClassDict objectForKey:key]53 forKey:key];54 }55 56 NSString *newkey = @&newKey&;57 NSString *newValue = @&This is a new Value.&;58 [myNewDict setObject:newValue forKey:newkey];59 60  //遍历myNewDict61 NSLog(@&***遍历字典myNewDict如下:&);62  for(id key inmyNewDict)63 {64 NSLog(@&key: %@ ,value: %@&,key,[myNewDict objectForKey:key]);65 }  NSLog(@&***遍历字典myNewDict结束。&);  //删除元素69 [myNewDict removeObjectForKey: @&newKey&];  //遍历myNewDict72 NSLog(@&***遍历字典myNewDict如下:&);   for(id key inmyNewDict)  {  NSLog(@&key: %@ ,value: %@&,key,[myNewDict objectForKey:key]);  }  NSLog(@&***遍历字典myNewDict结束。&);  [pool drain];   return 0;  }// 输出结果(省略日期 时间等信息)修改数据: Elf Sundae***遍历字典myClassDict如下:key: my3 ,value: Elf Sundaekey: my4 ,value: No Name found.key: my1 ,value: No Name found.key: my2 ,value: No Name found.***遍历字典myClassDict结束。***遍历字典myNewDict如下:key: newKey ,value: This is a new Value.key: my3 ,value: Elf Sundaekey: my4 ,value: No Name found.key: my1 ,value: No Name found.key: my2 ,value: No Name found.***遍历字典myNewDict结束。***遍历字典myNewDict如下:key: my3 ,value: Elf Sundaekey: my4 ,value: No Name found.key: my1 ,value: No Name found.key: my2 ,value: No Name found.***遍历字典myNewDict结束。
读取和写入plist文件plist文件是标准的xml文件,在cocoa中可以很简单地使用。这里介绍一下使用方法: 以下代码在Mac和iPhone中均适用。 写入plist文件:   NSMutableDictionary* dict = [ [ NSMutableDictionary alloc ] initWithContentsOfFile:@&/Sample.plist& ];        [ dict setObject:@&Yes& forKey:@&RestartSpringBoard& ];        [ dict writeToFile:@&/Sample.plist& atomically:YES ]; 读取plist文件:   NSMutableDictionary* dict =  [ [ NSMutableDictionary alloc ] initWithContentsOfFile:@&/Sample.plist& ];        NSString* object = [ dict objectForKey:@&RestartSpringBoard& ];    
IPhone之NSBundle的使用bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in). 对应bundle,cocoa提供了类NSBundle.我们的程序是一个bundle. 在Finder中,一个应用程序看上去和其他文件没有什么区别. 但是实际上它是一个包含了nib文件,编译代码,以及其他资源的目录. 我们把这个目录叫做程序的main bundle通过使用下面的方法得到程序的main bundleNSBundle *myBundle = [NSBundle mainBundle];一般我们通过这种方法来得到bundle.如果你需要其他目录的资源,可以指定路径来取得bundleNSBundle *goodBgoodBundle = [NSBundle bundleWithPath:@&~/.myApp/Good.bundle&];一旦我们有了NSBundle 对象,那么就可以访问其中的资源了// Extension is optionalNSString *path = [goodBundle pathForImageResource:@&Mom&];NSImage *momPhoto = [[NSImage alloc] initWithContentsOfFile:path];NSBundle有很多的用途.在这章中, NSBundle负责(在后台)加载nib文件. 我们也可以不通过NSWindowController来加载nib文件, 直接使用NSBundle:BOOL successful = [NSBundle loadNibNamed:@&About& owner:someObject];注意噢, 我们指定了一个对象someObject作为nib的File's Owner使用initWithContentsOfFile时,文件路径的写法 使用initWithContentsOfFile方法可以通过读取一个文件的内容来初始化对象。 但文件的路径应该怎么确定呢? 可以使用NSBundle的对象来获取。 例如当前程序所在目录下有个文件re.xml,我们要将该文件的内容做为NSData的数据源来初始化一个NSData对象,可以用下面的方法来实现:NSString *filePath = [[NSBundle mainBundle] pathForResouse:@&re& ofType:@&xml&]; NSData *data = [[NSData alloc] initWithContentsOfFile:filePath];读取plist中的内容:NSString *dataPath = [[NSBundle mainBundle] pathForResource:@&Data& ofType:@&plist&]; self.data = [NSArray arrayWithContentsOfFile:dataPath];删除本地文件NSString * thePath=[self getUserDocumentDirectoryPath]; NSMutableString * fullPath=[[[NSMutableString alloc]init]autorelease]; [fullPath appendString:thePath]; NSString * idString=[idArray objectAtIndex:indexPath.row]; NSString * coverName=[NSString stringWithFormat:@&/%@.jpg&,idString]; [fullPath appendString:coverName]; NSFileManager *defaultM defaultManager = [NSFileManager defaultManager];- (BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error    BOOL boolValue=[defaultManager removeItemAtPath: fullPath error: nil];  if (boolValue) {  NSLog(@&remove cover image ok&); }  - (NSString*)getUserDocumentDirectoryPath {  NSArray* array = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);  if([array count])   return [array objectAtIndex: 0];  else return @&&; }
IPhone之NSBundle的使用NSBundle的对象可以获取应用程序安装目录的附件。 附件包括了,当前应用程序下,所有的文件。(图片、属性列表等)获取XML文件NSString *filePath = [[NSBundle mainBundle]pathForResouse:@&re& ofType:@&xml&];NSData *data = [[NSData alloc]initWithContentsOfFile:filePath];获取属性列表NSDictionary *dict = [NSDictionarydictionaryWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@&ViewControllers& ofType:@&plist&]];
NSBundle束,是一种特定的文件类型,其中的内容遵循特定的结构。NSBundle的一个主要作用是 获取Resources文件夹中的资源。使用主束来获取需要的资源文件:NSBundle *bundle = [NSBundle mainBundle]; NSString *plistPath = [bundle pathForResource:@&statedictionary& ofType:@&plist&];或者简写成一行:NSString *path = [[NSBundle mainBundle] pathForResource:@&sortednames& ofType:@&plist&]; NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
线程同步和线程异步有什么区别?(重要基础知识)打个比方,如果你在等一个人,同步的时候,你会一直等到她来了之后才做其他事情,这个过程除了等待你啥都不会做,异步的时候,你一边在等,可能一边玩游戏或者是看报纸什么的,一直到她到来,你的等待状态才会结束在实现上,同步的过程会阻塞进程的所有其他操作,将同步转换为异步的最常见方法则是将会阻塞进程的等待操作放入到一个新的进程中,同时为该等待操作添加一个监视器,在检测到等待操作完成的时候结束等待的进程。
异步调用异步调用就是你 喊 你朋友吃饭,你朋友说知道了,待会忙完去找你 ,你就去做别的了。 同步调用就是你 喊 你朋友吃饭,你朋友在忙,你就一直在那等,等你朋友忙玩了,你们一起去。
是否可以对表进行编辑[self.tableView setEditing:BOOL animated:YES];对表进行添加操作以后就表进行更新[self.tableView reloadData]; 
引用 引用第207楼haoxue于 14:33发表的&&:是否可以对表进行编辑[self.tableView setEditing:BOOL animated:YES];对表进行添加操作以后就表进行更新.......
拜托,这是我个人的学习笔记,供我个人使用的。请不要在里面乱写。 请各位不要在我的学习笔记里乱发表言论,这是我私人东西。大家可以学习、参考我写的资料。但请不要在里面乱写。
好东西啊。。 语法学习啦。。
拜托,这是我个人的学习笔记,供我个人使用的。请不要在里面乱写。 请各位不要在我的学习笔记里乱发表言论,这是我私人东西。大家可以学习、参考我写的资料。但请不要在里面乱写。
UIapplication在开发过程中我们需要一些全局对象来将程序的各个部分连接起来,这些全局对象中最重要的就是UIApplication对象。但在实际编程中我们并不直接和UIApplication对象打交道,而是和其代理打交道。UIApplication 是iPhone应用程序的开始并且负责初始化并显示UIWindow,并负责加载应用程序的第一个UIView到UIWindow窗体中。 UIApplication的另一个任务是帮助管理应用程序的生命周期,而UIApplication通过一个名字为 UIApplicationDelegate的代理类来履行这个任务。尽管UIApplication会负责接收事件,而 UIApplicationDelegate则决定应用程序如何去响应这些事件,UIApplicationDelegate可以处理的事件包括应用程序 的生命周期事件(比如程序启动和关闭)、系统事件(比如来电、记事项警告),本文会介绍如何加载应用程序的UIView到UIWindow以及如何利用 UIApplicationDelegate处理系统事件。通 常对于UIApplication读者是没必要修改它的,只需要知道UIApplication接收系统事件即可,而如何编写代码来处理这些系统事件则是 程序员的工作。处理系统事件需要编写一个继承自UIApplicationDelegate接口的类,而UIApplicationDelegate接口 提供生命周期函数来处理应用程序以及应用程序的系统事件。如 果利用Xcode的模板创建项目,Xcode会为程序员创建继承自UIApplicationDelegate的类,但不会自动实现继承自 UIApplicationDelegate的可选的事件处理函数。如果读者创建一个名为“TestUIApplication”的项目,Xcode会自 动创建TestUIApplicationAppDelegate.h和TestUIApplicationAppDelegate.m文件,文件的声明 如下:@interface TestUIApplicationAppDelegate : NSObject &UIApplicationDelegate&而应用程序的UIApplication则被定义在MainWindow.xib文件中,并且有一个作为outlet的UIApplicationDelegate引用。iPhone 并不是多任务的操作系统,所以应用程序很容易受到打扰,比如一个来电可能导致应用程序失去焦点,如果这个时候接听了电话,那么应用程序会自动终止运行。还 有很多其它类似的事件会导致iPhone应用程序失去焦点,在应用程序失去焦点前会调用委托类的 applicationWillResignActive()方法,而应用程序再次获取到焦点的时候会调用 applicationDidBecomeActive()方法。比如在运行应用程序的时候锁屏会调用委托类的 applicationWillResignActive()方法,而当屏幕被解锁的时候,又会调用 applicationDidBecomeActive()方法。另 外一个非常重要的方法就是applicationDidReceiveMemoryWarning(),因为iPhone设备只有有限的内存,如果为应用 程序分配了太多内存操作系统会终止应用程序的运行,但在终止之前操作系统会通过先调用委托类的 applicationDidReceiveMemoryWarning()方法警告应用程序,在UIApplication接收到这个事件后它会传递给 委托类的applicationDidReceiveMemoryWarning()方法,委托类在这个方法内可以进行释放内存的操作以防止操作系统强制 终止应用程序的运行。现在来看协议中定义的这些需要实现的方法分别是什么作用:1、- (void)applicationWillResignActive:(UIApplication *)application说明:当应用程序将要入非活动状态执行,在此期间,应用程序不接收消息或事件,比如来电话了2、- (void)applicationDidBecomeActive:(UIApplication *)application说明:当应用程序入活动状态执行,这个刚好跟上面那个方法相反3、- (void)applicationDidEnterBackground:(UIApplication *)application说明:当程序被推送到后台的时候调用。所以要设置后台继续运行,则在这个函数里面设置即可4、- (void)applicationWillEnterForeground:(UIApplication *)application说明:当程序从后台将要重新回到前台时候调用,这个刚好跟上面的那个方法相反。5、- (void)applicationWillTerminate:(UIApplication *)application说明:当程序将要退出是被调用,通常是用来保存数据和一些退出前的清理工作。这个需要要设置UIApplicationExitsOnSuspend的键值。6、- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application说明:iPhone设备只有有限的内存,如果为应用程序分配了太多内存操作系统会终止应用程序的运行,在终止前会执行这个方法,通常可以在这里进行内存清理工作防止程序被终止7、- (void)applicationSignificantTimeChange:(UIApplication*)application说明:当系统时间发生改变时执行8、- (void)applicationDidFinishLaunching:(UIApplication*)application说明:当程序载入后执行9、- (void)application:(UIApplication)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame说明:当StatusBar框将要变化时执行10、- (void)application:(UIApplication*)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientationduration:(NSTimeInterval)duration说明:当StatusBar框方向将要变化时执行11、- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url说明:当通过url执行12、- (void)application:(UIApplication*)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation说明:当StatusBar框方向变化完成后执行13、- (void)application:(UIApplication*)application didChangeSetStatusBarFrame:(CGRect)oldStatusBarFrame说明:当StatusBar框变化完成后执行&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
scrollView的几个属性contentSize contentOffset contentInsetcontentSize是scrollview可以滚动的区域,比如frame = (0 ,0 ,320 ,480) contentSize = (320 ,960),代表你的scrollview可以上下滚动,滚动区域为frame大小的两倍。contentOffset是scrollview当前显示区域顶点相对于frame顶点的偏移量,比如上个例子你拉到最下面,contentoffset就是(0 ,480),也就是y偏移了480contentInset是scrollview的contentview的顶点相对于scrollview的位置,例如你的contentInset = (0 ,100),那么你的contentview就是从scrollview的(0 ,100)开始显示另外UITableView是UIScrollView的子类,它们在上述属性又有所不同,tabelview的contentsize是由它的下列方法共同实现的- (NSInteger)numberOfS- (NSInteger)numberOfRowsInSection:(NSInteger)- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexP- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)它会自动计算所有的高度和来做为它的contentsize的height。例如你在delegate方法- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {    return 100;}那么你的tabelview的contentsize就是(320, 4400)
UIScrollView 原理详解http://blog.csdn.net/ch_soft/article/details/6947695
iPhone开发:UIScrollView分页算法    在使用 UIScrollView 分页的时候我们如何确定当前是第几页?     首先需要开启分页设置     scrollView.pagingEnabled = YES;     然后我们在委托的类上实现以下方法     - (void) scrollViewDidScroll:(UIScrollView *)sender {            // 得到每页宽度            CGFloat pageWidth = sender.frame.size.width;            // 根据当前的x坐标和页宽度计算出当前页数            int currentPage = floor((sender.contentOffset.x - pageWidth / 2) / pageWidth) + 1;}    
frame.origin.x  的意思和作用?   scrollView.frame一个view的frame 包含它的矩形形状(size)的长和宽。和它在父视图中的坐标原点(origin)x和y坐标  frame  框架origin就是所謂的起點位置frame在ios里并不是一个具体的对象,他只是一些控件的一个属性。frame的值就是一个CGRect 包括(originX,originY,width,height)。originX和originY对应着该对象在其superview中的坐标,也就是说他是一个相对坐标。view 的frame是view在它的super view 的位置与尺寸。UIView中bounds和frame的差别? 什么是绝对坐标值,相对坐标值?绝对坐标是:X,Y    就是相对于坐标原点的。 bounds是指这个view在它自己坐标系的坐标和大小 而frame指的是这个view在它superview的坐标系的坐标和大小,区别主要在坐标系这一块。frame 是相对坐标。bounds是绝对坐标。很明显,bounds的原点是(0,0)点,而frame的原点却是任意的。frame 如果一个按钮,是在表格里,按钮的frame 的坐标也是相对的,并不是相对屏幕,也就是说是相对坐标,不是绝对坐标。很明显一个是自己为原点的坐标系,一个是以屏幕为原点的坐标系。
#pragma mark public methods- (void)layoutForGoods:(NSArray *)goods{    for (int i=0; i&3; ++i) {        int xOffset, yO        xOffset = i % 3; //  %取余运算符, 求余运算符        yOffset = i / 3; //  /除法运算符  //frame相对坐标,而frame的原点却是任意的。是一个以自己为原点的坐标系。  //bounds是绝对坐标。bounds的原点是(0,0)点,是以屏幕为原点的坐标系。        CGRect frame = CGRectMake(33 + xOffset*(GoodsWidth + GoodsWidthPadding),                                   12+yOffset*(GoodsHeight + GoodsHeightPadding),                                  GoodsWidth, GoodsHeight);        CButton* btn = [[[CButton alloc] initWithFrame:frame] autorelease];        btn.normalImage = [UIImage imageNamed:@&test__1.png&];        btn.title = @&白色马克杯&;        btn.value = 28.0;  //是指什么?        [self addSubview:btn];    }}&&&&&&&&&&&&     除法运算符“/”。二元运算符,具有左结合性。参与运算的量均为整型时,结果为整型,舍去小数。如果运算量中有一个为实型,结果为双精度实型。例如:5/2=2,1/2=0 5/2.0=2.5      求余运算符“%”,二元运算符,具有左结合性。参与运算的量均为整型。求余运算的结果等于两个数相除后的余数。
受教了。。。。。。。支持一下,学习中。以后也要经常做笔记。养成一个好的习惯。。。
markmarkmark
很好的知识点,谢谢分享
UITableView的重要基础知识
关于 addTarget 指定响应函数的一个小问题                与 UIButton 对象不同属于一个类中的函数,也可以指定为 addTarget 响应的函数的,方法@select(extraMethod)-(void)extraMethod{    [extraClass method];  }          
程序员一定要注意身体啊!!!
mark 以后再来看。
3、添加UITableViewUITableView&&*table1=[[UITableView alloc] initWithFrame:CGRectMake(0, 0.00, 300, 250)];&table1.autoresizingMask=UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHtable1.backgroundColor=[UIColor redColor];//添加到view窗体上[view addSubview:table1];&table1.delegate=&table1.dataSource=4、取消点击动画&[tableView deselectRowAtIndexPath:indexPath animated:YES];5、滚动路径标识,直至指数连续接收器在屏幕上的特定位置- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated Parameters&&&&indexPath索引路径标识在其行的索引,其部分指标表视图行。&&&&scrollPosition&&&&&一个常数,在接收标识表查看行(上,中,下)的相对位置滚动时结束。&&&&animated&&&&是如果你要动画在位置改变,没有是否应立即生效。&&&&实例代码:float height=216.0;CGRect frame=m_pTableView.frame.size=CGSizeMake(frame.size.width, frame.size.height - height);[UIView beginAnimations:@&Curl&context:nil];//动画开始&&&[UIView setAnimationDuration:0.30];&&&[UIView setAnimationDelegate:self];&&[m_pTableView setFrame:frame];&&[m_pTableView scrollToRowAtIndexPath:selectedIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];[UIView commitAnimations];&
好东西,收藏之,谢LZ!!!!
XCode中的API文档(iPhone开发中Xcode帮助文档)解iPhone开发中Xcode帮助文档是本文要介绍的内容,开发 iPhone 应用程序首先需要理解 Cocoa Touch 的应用开发框架。程序中想要实现什么样的功能,需要使用怎样的API,只有有相应的API才能实现你的想法,创意。这个API的文档可是从ADC的 iPhone Dev Center 得到、如果安装了 Xcode 可以直接在菜单中点击「Documentation」,就可以了,如下图所示。
左边显示了现在可以利用的文档。刚安装好 iPhone SDK 的时候,相应的文档应该还没有安装上,需要重新下载:点击「SUBSCRIBE」按钮就开始下载了。 你可以随时下载,并设定自动下载 — 通过下面的齿轮按钮可以设置下载的间隔。只是下载/安装比较耗费CPU资源,所以尽量避开在开发的过程中下载。 点击右上角的标签按钮,可以检索各种文档。如果确实是你 iPhone 中使用的API时,显示如下图一样,左边的列表与上面标签显示的一样为「iPhone OS x.x Library」,如图:
另外,Mac OS X 用的 Cocoa 与 iPhone 用的 Cocoa Touch 有些不一样,虽然有的API名字相同,但是机能或多或少有些差别的有很多,所以开发的时候最好注意了。 小结:了解iPhone开发中Xcode帮助文档的内容介绍完了,希望本文对你有所帮助
用户被禁言,该主题自动屏蔽!
-、建立 UITableView DataTable =[[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)]; [DataTable setDelegate:self]; [DataTable setDataSource:self]; [self.view addSubview:DataTable]; [DataTable release];二、UITableView各Method说明 //Section总数-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ returnTitleD}//Section Titles//每个section显示的标题-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return@&&;}//指定有多少个分区(Section),默认为1-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return4;}//指定每个分区中有多少行,默认为1-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{}//绘制Cell-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {staticNSString *SimpleTableIdentifier =@&SimpleTableIdentifier&;      UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:                             SimpleTableIdentifier];    if(cell ==nil) {          cell =[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault                                       reuseIdentifier: SimpleTableIdentifier] autorelease]; } cell.imageView.image=//未选cell时的图片cell.imageView.highlightedImage=highlightI//选中cell后的图片cell.text=//.....return}//行缩进-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{ NSUInteger row =[indexPath row]; return}//改变行的高度-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{    return40;}//定位[TopicsTable setContentOffset:CGPointMake(0, promiseNum *44+Chapter *20)];//返回当前所选cellNSIndexPath *ip =[NSIndexPath indexPathForRow:row inSection:section];[TopicsTable selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionNone];[tableView setSeparatorStyle:UITableViewCellSelectionStyleNone];//选中Cell响应事件-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES];//选中后的反显颜色即刻消失}//判断选中的行(阻止选中第一行)-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{    NSUInteger row =[indexPath row];    if(row ==0)        return       returnindexP}//划动cell是否出现del按钮-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {}//编辑状态-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyleforRowAtIndexPath:(NSIndexPath *)indexPath{}[topicsTable setContentSize:CGSizeMake(0,controller.promiseNum *44)];//右侧添加一个索引表-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{}//返回Section标题内容-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{}//自定义划动时del按钮内容-(NSString *)tableView:(UITableView *)tableViewtitleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath//跳到指的row or section[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];三、在UITableViewCell上建立UILable多行显示-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    staticNSString *CellIdentifier =@&Cell&;       UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:CellIdentifier];    if(cell ==nil) {        cell =[[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];  UILabel *Datalabel =[[UILabel alloc] initWithFrame:CGRectMake(10, 0, 320, 44)];  [Datalabel setTag:100];  Datalabel.autoresizingMask =UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleH  [cell.contentView addSubview:Datalabel];  [Datalabel release]; }
UILabel *Datalabel =(UILabel *)[cell.contentView viewWithTag:100]; [Datalabel setFont:[UIFont boldSystemFontOfSize:18]]; Datalabel.text =[data.DataArray objectAtIndex:indexPath.row]; cell.accessoryType =UITableViewCellAccessoryDisclosureI    return}//选中cell时的颜色typedef enum{    UITableViewCellSelectionStyleNone,    UITableViewCellSelectionStyleBlue,    UITableViewCellSelectionStyleGray} UITableViewCellSelectionStyle //cell右边按钮格式typedef enum{    UITableViewCellAccessoryNone,                   //don't show any accessory viewUITableViewCellAccessoryDisclosureIndicator,    //regular chevron. doesn't trackUITableViewCellAccessoryDetailDisclosureButton, //blue button w/ chevron. tracksUITableViewCellAccessoryCheckmark               //checkmark. doesn't track} UITableViewCellAccessoryType//是否加换行线typedef enum{    UITableViewCellSeparatorStyleNone,    UITableViewCellSeparatorStyleSingleLine} UITableViewCellSeparatorStyle//改变换行线颜色tableView.separatorColor =[UIColor blueColor];
拜托,这是我个人的学习笔记,供我个人使用的。请不要在里面乱写。 请各位不要在我的学习笔记里乱发表言论,这是我私人东西。大家可以学习、参考我写的资料。但请不要在里面乱写。
警告:这是我个人的学习笔记,供我个人使用的。请不要在里面乱写! 请不要在我的学习笔记里乱发表言论,这是我私人东西。
iPhone开源项目汇总(更新版)扫描wifi信息:
条形码扫描:
tcp/ip的通讯协议:
voip/sip:
google gdata
720全景显示panoramagl
jabber client
image processing
json编码解码: base64编码解码: xml解析: 安全保存用户密码到keychain中: 加载等待特效框架(private api): http等相关协议封装: 下拉刷新代码: 异步加载图片并缓存代码: iphone TTS: iphone cook book 源码: iphone正则表达式: OAuth认证:   蓝牙协议栈: 语音识别: ShareKit: 日历控件:
zlib, openssl: 地球显示信息:
很好的学习笔记
头文件testViewController.h如下#import &UIKit/UIKit.h&@interface testViewController : UIViewController {     IBOutlet UILabel*}@property(nonatomic,retain)UILabel*@endtestViewController.m如下#import &testViewController.h&@implementation testViewController@- (void)viewDidLoad {    //UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 20.0, 200.0, 50.0)];   //消掉注释label属性 起作用   //设置显示文字    label.text = @&test&;      //设置字体   //label.font = [UIFont boldSystemFontOfSize:20];   //设置文字颜色   //label.textColor = [UIColor orangeColor];   //设置文字位置   //label.textAlignment = UITextAlignmentR   //label.textAlignment = UITextAlignmentC   //设置字体大小适应label宽度   //label.adjustsFontSizeToFitWidth = YES;   //设置label的行数   //label.numberOfLines = 2;   //设置高亮   //label.highlighted = YES;   //label.highlightedTextColor = [UIColor orangeColor];   //设置阴影   //label.shadowColor = [UIColor redColor];   //label.shadowOffset = CGSizeMake(1.0,1.0);   //设置是否能与用户进行交互 //label.userInteractionEnabled = YES;   //设置label中的文字是否可变,默认值是YES   //label.enabled = NO;   //设置文字过长时的显示格式 //label.lineBreakMode = UILineBreakModeMiddleT//截去中间   //  typedef enum {   //      UILineBreakModeWordWrap = 0,   //      UILineBreakModeCharacterWrap,   //      UILineBreakModeClip,//截去多余部分   //      UILineBreakModeHeadTruncation,//截去头部   //      UILineBreakModeTailTruncation,//截去尾部   //      UILineBreakModeMiddleTruncation,//截去中间   //  } UILineBreakM   //如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为   //label.baselineAdjustment = UIBaselineAdjustmentN   //  typedef enum {   //      UIBaselineAdjustmentAlignBaselines,   //      UIBaselineAdjustmentAlignCenters,   //      UIBaselineAdjustmentNone,   //  } UIBaselineA       [super viewDidLoad];   }   - (void)didReceiveMemoryWarning {      // Releases the view if it doesn't have a superview.       [super didReceiveMemoryWarning];    // Release any cached data, images, etc that aren't in use.   }   - (void)viewDidUnload {      // Release any retained subviews of the main view.   // e.g. self.myOutlet =   }   - (void)dealloc {    [label release];      [super dealloc];   }   @end
多使用宏定义常量。tag,frame大小,一些判断标志位。#define kIndexValueTag 1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&* assign: 简单赋值,不更改索引计数(Reference Counting)。  * copy: 建立一个索引计数为1的对象,然后释放旧对象  * retain:释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1 * 使用assign: 对基础数据类型 (NSInteger)和C数据类型(int, float, double, char,等)  * 使用copy: 对NSString  * 使用retain: 对其他NSObject和其子类  copy是创建一个新对象,retain是创建一个指针,引用对象计数加1。1.readonly表示这个属性是只读的,就是只生成getter方法,不会生成setter方法.2.readwrite,设置可供访问级别3.retain,是说明该属性在赋值的时候,先release之前的值,然后再赋新值给属性,引用再加1。4.nonatomic,非原子性访问,不加同步,多线程并发访问会提高性能。先释放原先变量,再将新变量retaii然后赋值;       注意,如果不加此属性,则默认是两个访问方法都为原子型事务访问。
用户被禁言,该主题自动屏蔽!
ios保存数据和读取数据的方法http://www./post/143/
拜托,这是我个人的学习笔记,供我个人使用的。请不要在里面乱写。 请各位不要在我的学习笔记里乱发表言论,这是我私人东西。大家可以学习、参考我写的资料。但请不要在里面乱写。
用户被禁言,该主题自动屏蔽!
mark good!
学习了~~~~~~~
@property (copy, nonatomic) NSString *什么是assign,copy,retain之间的区别?assign: 简单赋值,不更改索引计数(Reference Counting)。 copy: 建立一个索引计数为1的对象,然后释放旧对象 retain:释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1 retain的实际语法为:- (void)setName:(NSString *)newName {   &&if (name != newName) {      &&[name release];      &&name = [newName retain];      &&// name’s retain count has been bumped up by 1   &&}}使用assign: 对基础数据类型 (NSInteger,CGFloat)和C数据类型(int, float, double, char, 等等) 使用copy: 对NSString 使用retain: 对其他NSObject和其子类 nonatomic关键字:atomic是Objc使用的一种线程保护技术,基本上来讲,是防止在写未完成的时候被另外一个线程读取,造成数据错误。而这种机制是耗费系统资源的,所以在iPhone这种小型设备上,如果没有使用多线程间的通讯编程,那么nonatomic是一个非常好的选择。为什么要在覆盖init的时候需要检查是否在父类中作初始化,例如:- (id)init{if(self = [super init]){}}或- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {   &&if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {       &&// Custom initialization   &&}   &&}主要是将本地对象用父类的init进行初始化,其中的等号“=”另一方面检查了是不是成功进行了初始化。不仅仅是init等初始化对象,还有其他一些方法(Method)是需要对自己的父类打声招呼得,例如:- (void)viewDidLoad {   &&[super viewDidLoad];}那这个没有super这句会怎么样呢?没事,一样用。这个是一个delegate,所以需要收听的类应该会收听到的。但是既然缺省的方法就是这么写的,我们也没有必要特意去删除掉这个super方法。
NSString *aString = [[NSString alloc] initWithFormat:@&这也是个NS字符串!&];*initWithFormat是其中一个初始化方法,常用的还有//从一个文件读取需要的内容- (id)initWithContentsOfFile:(NSString *)path encoding:(NSStringEncoding)enc error:(NSError **)error//从一个地址读取需要的内容- (id)initWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)enc error:(NSError **)error*以上方法得到的NSString的retain值为1,所以记得release掉阿~~NSString *aString = @&This is a NSString&;设置一个UIView的标题:[UIView setTitle:aString];[UIView setTitle:@&标题&];UIView.title = aSNSInteger其实是一个自动定义,在32位中为int,而64位中为long。CGFloat的原理类似
iphone --delegate(委托)的机制委托(Delegate)机制:就是通过声明对象A为对象B的代理,从而达到在A中改变B功能的机制。委托是一种避免对复杂的UIKit对象(比如缺省的UIApplication对象)进行子类化的机制。在这种机制下,您可以不进行子类化和方法重载,而是将自己的定制代码放到委托对象中,从而避免对复杂对象进行修改。当您感兴趣的事件发生时,复杂对象会将消息发送给您定制的委托对象。您可以通过这种“挂钩”执行自己的定制代码,实现需要的行为。delegate  类似于interface 。特别注意:delegate往往是assign方式的属性而不是retain方式的属性,赋值不会增加引用计数,就是为了防止delegation两端产生不必要的循环引用。
查看完整版本: [--
Powered by
Gzip disabledYou can

我要回帖

更多关于 box shadow inset 的文章

 

随机推荐