iOS 笔记( 12-7-11)

将最近学习ios做的笔记整理一下

A\

NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames"
                    ofType:@"plist"];
获取属性文件的路径
NSDictionary *dict = [[NSDictionary alloc]
                          initWithContentsOfFile:path];
将属性文件保存在字典中

B\
didSelectRowAtIndexPath没有响应:1,看delegate是否设置,
2,是否定义了willSelectRowAtIndexPath,返回nil时也不会调用该方法。


[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:kDefaultTabSelection], kWhichTabPrefKey,nil]]和
[[NSUserDefaults standardUserDefaults] setObject:classNames forKey:kTabBarOrderPrefKey]的区别,前一个时注册相当于创建一个默认项,后一个是设置默认项的值。


C\
取消用户交互:
shutdown the user interaction of a view(such as button click,textfield input),set the user interaction property NO

D\
代理的实现:
@protocol RecentSearchesDelegate
// Sent when the user selects a row in the recent searches list.
- (void)recentSearchesController:(RecentSearchesController *)controller didSelectString:(NSString *)searchString;
@end

1、in class:RecentSearchesController:
{id <RecentSearchesDelegate> delegate; }//*********************************************
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Notify the delegate if a row is selected.
    [delegate recentSearchesController:self didSelectString:[displayedRecentSearches objectAtIndex:indexPath.row]];          //********************************************
}

2、in class:
ToolbarSearchViewController 
<RecentSearchesDelegate>               //*********************************************

- (void)recentSearchesController:(RecentSearchesController *)controller didSelectString:(NSString *)searchString {
    
    // The user selected a row in the recent searches list (UITableView).
    // Set the text in the search bar to the search string, and conduct the search.
    //
    searchBar.text = searchString;
    [self finishSearchWithString:searchString];
}

E\
搜索栏中实现匹配的简单方式:使用NSPredicate
- (void)filterResultsUsingString:(NSString *)filterString {
    // If the search string is zero-length, then restore the recent searches,
    // otherwise create a predicate to filter the recent searches using the search string.
    if ([filterString length] == 0) {
        self.displayedRecentSearches = recentSearches;
    }
    else {
        NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"self BEGINSWITH[cd] %@", filterString];
        NSArray *filteredRecentSearches = [recentSearches filteredArrayUsingPredicate:filterPredicate];
        self.displayedRecentSearches = filteredRecentSearches;
    }
    [self.tableView reloadData];
}

F\

应用程序沙盒:ios每一个应用程序在设备上都是一个独立的孤岛,相关的数据和文件都是在沙盒内部的,沙盒内主要有:document,cache,library,NSBundle等,沙盒根目录是是一个homedirectory.NSBundle主要包括项目的可执行文件,资源文件,配置文件,本地化文件等

I\

three20url映射规则:http://three20.info/article/2010-10-06-URL-Based-Navigation

J\

ios的内存管理:不要在init和dealloc方法中使用访问器方法setter和getter方法,因为如果子类重写了父类的访问器方法时,可能会导致内存泄漏(例如子类的setter方法,赋给特性另外一个值,在delloc方法中使用self.var=nil时,调用子类的setter方法,导致该值不能被释放,从而发生内存泄漏)。

H\

[UIScreen mainScreen]bounds]和[UIScreen mainScreen] applicationFrame],前者返回整个屏幕的宽度,包括状态栏,后者不包括状态栏。(iphone前者高度为480,后者460);


K\

调用dismissModalViewControllerAnimated将展示得视图从原视图中移去时,原视图的坐标默认变为(0,0),目前还没有方法可以改变此机制。

L\在view中获取控制器,获取当前视图的view controller:
- (UIViewController*)viewController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController*)nextResponder;
        }
    }
    return nil;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值