狗狗地图项目总结

来源:互联网 发布:加入农村淘宝的好处 编辑:程序博客网 时间:2024/04/30 00:13
归档:


+ (MXUser *)currentUser{
    NSData *encodedUser = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_key"];
    MXUser *user = (MXUser *)[NSKeyedUnarchiver unarchiveObjectWithData:encodedUser];
    return user;
}


类别:可以不需要继承,直接扩展方法,一般用于一些方法调用的方法
- (void)showText:(NSString*)str
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.removeFromSuperViewOnHide = YES;
    hud.mode = MBProgressHUDModeText;
    hud.labelText = str;
    [hud hide:YES afterDelay:1.5];
    
    
}


3.SVPUllReFresh
 self.refreshControl = [[UIRefreshControl alloc] init];
    [self.refreshControl addTarget:self action:@selector(refreshData:) forControlEvents:UIControlEventValueChanged];
    [_tableView addSubview:self.refreshControl];
    
    [_tableView addInfiniteScrollingWithActionHandler:^{
        NSInteger offsetId = 0;
        if(weakSelf.messageMuArr.count>0){
            UserMessage *temp = [weakSelf.messageMuArr lastObject];
            offsetId = temp.id;
        }
        
        [weakSelf getListData:offsetId];
    }];
    
    [_tableView triggerInfiniteScrolling];
}
- (void)getListData:(NSInteger)page
{
    [UserMessage messageListWithOffsetId:page success:^(NSArray *userMessageList, BOOL hasMore) {
        if (0 == page) {
            [_messageMuArr removeAllObjects];
        }
        [_messageMuArr addObjectsFromArray:userMessageList];
        [_tableView reloadData];
        [self.refreshControl endRefreshing];
        [_tableView.infiniteScrollingView stopAnimating];
        _tableView.showsInfiniteScrolling = hasMore;
    } failure:^(NSError *error) {
        [self showError:error];
        [self.refreshControl endRefreshing];
        [_tableView.infiniteScrollingView stopAnimating];
    }];
}




//重用formatter
- (NSDateFormatter *)formatter {
    if (! _formatter) {
        _formatter = [[NSDateFormatter alloc] init];
        _formatter.dateFormat = @"yyyy.MM.dd HH:mm:ss"; // twitter date format
    }
    return _formatter;
    
}


故事版
 UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    
//    DogFriendsDetailViewController*dogFriendsVC = [storyboard instantiateViewControllerWithIdentifier:@"DogFriendsDetailViewController"];




 [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:selectedIndex inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone];


 _dogImageView.layer.cornerRadius = 49;
    _dogImageView.layer.masksToBounds = YES;


 NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:kmStr];
            [attrString addAttribute:NSFontAttributeName
                               value:[UIFont systemFontOfSize:20.0f]
                               range:NSMakeRange(kmStr.length-2, 2)];
            [cell.kilometreLab setAttributedText:attrString];
 __weak DogFriendsViewController *weakSelf = self; //block里面为弱引用




本地推送




JSONMOdel


@interface MXUser :JSONModel
这是一个可以讲json 数据转换为对象的三方库。很好用
只要模型的字段和接口的字段匹配就可以读数据
@property(nonatomic, strong) NSString<Optional> *mastername; //主人名称
@property(nonatomic, assign) Gender gender;
optional 是有些字段是可选的。
如果字段有冲突可以用


+(JSONKeyMapper*)keyMapper
{
    return [[JSONKeyMapper alloc] initWithDictionary:@{
                                                       @"uid": @"userId",
                                                       @"name": @"phone"
                   
如果是一个字典


MXUser *user = [[MXUser alloc] initWithDictionary:userAttributes error:&error];
                                    }];
}
如果是一个数组:
 NSArray *categoryList = [QuestionCategory arrayOfModelsFromDictionaries:result error:&error];






+ (instancetype)sharedClient{
    static APIClient *_sharedClient = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedClient = [[APIClient alloc] initWithBaseURL:[NSURL URLWithString:kAPIBaseURLString]];
    });
    return _sharedClient;
}
0 0