简单的几个OC知识点

来源:互联网 发布:linux识别不到hba卡 编辑:程序博客网 时间:2024/05/02 17:49

1.关于系统自定义设值取值方法的理解

oc在接口文件里面使用

@property int a;

在实现文件里面使用

@synthesize int a;

来实现系统自动的设值取值函数,个人对这两句话暂时的理解是@property相当于将方法进行了声明

2.关于oc中访问方式

oc中的实例变量都是private,而方法都是public的,所以访问实例变量(就是类中定义的变量然后实例化以后才能使用的变量)的时候需要自己写设值取值函数。

3.本地推送消息无权限的问题

haven’t received permission from user
貌似是ios8改了以后的问题,可以在appDelegate.m文件中加入如下代码
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
else {
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge];
}

4. 如何将tableView设置为多个section

比如一个数组{1,5,4,6,7,3} 按照相应的顺序将大于5的放前面,小于等于5的放后面
预处理:
将数组改装成{{6,7},{1,5,4,3}},并将NSMutableArray* multitem[0]={6,7},NSMutableArray* multitem[1]={1,5,4,3};
然后

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{    return 2;}-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{//    return [[[BNRItemStore sharedStore] allItems]count];    return [multitem[section] count];}-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];//    NSArray* items=[[BNRItemStore sharedStore] allItems];    BNRItem* item=multitem[indexPath.section][indexPath.row];    cell.textLabel.text=[item description];    return cell;}

5.weak指针是不能作为变量的拥有者的

所以不存在
(_weak) UIView* view=[UIView alloc]init];
这样初始化为导致view无值,因为初始化了一个UIView,但是并没有strong指针指向相应的内存位置,从而会导致无拥有着而释放,从而view因为是弱指针且无指向从而释放。

6.ios8之后系统使用CLLocation定位没反应

这个需要进行一项配置,在plist中加入
NSLocationWhenInUseUsageDescription Boolean YES
然后在程序中调用

[self.locationManager requestWhenInUseAuthorization];[self.locationManager startUpdatingLocation];

就可以在程序使用期间调用CLLocation框架进行定位了,如果需要始终定位,在plist中加入
NSLocationAlwaysUsageDescription Boolean YES
在程序中调用

[self.locationManager requestAlwaysAuthorization][self.locationManager startUpdatingLocation];
0 0
原创粉丝点击