codecut iphone开发速查

来源:互联网 发布:it软件解决方案 编辑:程序博客网 时间:2024/04/30 01:37

使用tableview,textfield的内置方法一定要声明delegate。

 

为button设置字体颜色。

[cancelButtonsetTitleColor:[UIColorcolorWithRed:0.196green:0.310blue:0.522alpha:1.000]forState:UIControlStateNormal];

 

为button添加方法

[cancelButtonaddTarget:selfaction:@selector(clickCancel:)forControlEvents:UIControlEventTouchUpInside];

 

 

添加视图到后面and others.

[self.viewsendSubviewToBack:bgView]

addSubview,bringSubviewToFront, exchangeSubViewAtIndex:withSubviewAtIndex:,removeFromSuperview, subviews, superview, window.

 

actionsheet的使用  做交互的时候很有用

UIActionSheet*actions = [[UIActionSheetalloc]initWithTitle:nil delegate:self  cancelButtonTitle:nil   destructiveButtonTitle:nil  otherButtonTitles:nil];

- (void)willPresentActionSheet:(UIActionSheet*)actionSheet

- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

 

NSString 使用

NSString*myString =@"A String contant.";

    [myString stringByAppendingString:@"22"];

    [myString characterAtIndex:2];

    [myString cStringUsingEncoding:NSUTF8StringEncoding];

    [NSStringstringWithCString:[myStringcStringUsingEncoding:NSUTF8StringEncoding]encoding:NSUTF8StringEncoding];

    NSString*path = [NSHomeDirectory() stringByAppendingPathComponent:@"Document/file.txt"];

    NSError*error;

    if(![myString writeToFile:path atomically:YES encoding:NSUTF8StringEncodingerror: &error]) {

        NSString*inString = [NSString stringWithContentsOfFile:path usedEncoding:NSUTF8StringEncodingerror:error];

        if(!inString) {

            NSLog(@"error");

        }

    }

}

 

检测设备  用作判断

[[UIDevicecurrentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad

 

获得文件路径 读文件和取文件

AMBUNDLE(bundlePath)[[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:bundlePath]

 

uitableview

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

   

    UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell ==nil) {

        cell = [[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier]autorelease];

    }

    // Configure thecell...

    returncell;}

 

 

Tableviewcell 加载nib文件

staticNSString *CellIdentifier =@"Cell";  //cell是个标识符

    UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell ==nil) {

        cell = [[[NSBundlemainBundle]loadNibNamed:@"Cell"owner:selfoptions:nil]lastObject];

              cell.selectionStyle=UITableViewCellSelectionStyleNone;

更高单元格高度

- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

 

设置navigation的左右button

         self.navigationController.navigationBar.tintColor = [UIColorgreenColor];;

         self.navigationItem.rightBarButtonItem=BARBUTTON(@"Right",@selector(rightAction:));

         self.navigationItem.leftBarButtonItem=BARBUTTON(@"Left",@selector(leftAction:));


 发送NSnotification带数据

// Posting Notification with userinfoNSDictionary *orientationData;if(iFromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {    orientationData = [NSDictionary dictionaryWithObject:@"Right"                                                  forKey:@"Orientation"];}NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];[notificationCenter postNotificationName:@"Abhinav"                                  object:nil                                userInfo:orientationData];// Adding observer[[NSNotificationCenter defaultCenter] addObserver:self                                         selector:@selector(orientationChanged)                                             name:@"Abhinav"                                           object:nil];
- (void)orientationChanged:(NSNotification *)notification{    NSDictionary *dict = [notification userInfo];}