// 拉伸
self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_dealcell"]];
// 平铺
self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_dealcell"]];
保留两位小数
// 现价
self.currentPriceLabel.text = [NSString stringWithFormat:@"¥ %@", deal.current_price]
NSUInteger dotLoc = [self.currentPriceLabel.text rangeOfString:@"."].location
if (dotLoc != NSNotFound) {
// 超过2位小数
if (self.currentPriceLabel.text.length - dotLoc > 3) {
self.currentPriceLabel.text = [self.currentPriceLabel.text substringToIndex:dotLoc + 3]
}
}
- (BOOL)isEqual:(MTDeal *)other
{
return [self.deal_id isEqual:other.deal_id];
}
使用fmdb要用导入libsqlite3.tbd
cell会有复用,当上下滑动tableView或者collectionView的时候,前后cell会复用,导致很多错误现象出现,我们需要把这个东西写在模型里面,通过控制模型的属性来控制cell的样式
例如在- (void)setDeal:(MTDeal *)deal中,这么写
// 根据模型属性来控制cover的显示和隐藏
self.cover.hidden = !deal.isEditting
// 根据模型属性来控制打钩的显示和隐藏
self.checkView.hidden = !deal.isChecking
因为上下拉动tableview或者collectionView的时候会加载这个方法来获得内容,那我们只要让他和model绑定就不出现这个错误了
if (request != self.lastRequest) return;
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
[self viewWillTransitionToSize:CGSizeMake(collectionView.width, 0) withTransitionCoordinator:nil];
self.collectionView.footerHidden = (self.totalCount == self.deals.count);
self.noDataView.hidden = (self.deals.count != 0);
return self.deals.count;
}
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = @"yyyy-MM-dd";
NSDate *dead = [fmt dateFromString:self.deal.purchase_deadline];
dead = [dead dateByAddingTimeInterval:24 * 60 * 60];
NSDate *now = [NSDate date];
NSCalendarUnit unit = NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute;
NSDateComponents *cmps = [[NSCalendar currentCalendar] components:unit fromDate:now toDate:dead options:0];
if (cmps.day > 365) {
[self.leftTimeButton setTitle:@"一年内不过期" forState:UIControlStateNormal];
} else {
[self.leftTimeButton setTitle:[NSString stringWithFormat:@"%ld天%ld小时%ld分钟", (long)cmps.day, (long)cmps.hour, (long)cmps.minute] forState:UIControlStateNormal];
}
涉及到数据库的用工具类,提供方法即可
将一个模型存到数据库中,要将这个模型转为NSData才行,
例如添加一个收藏时:
+ (void)addCollectDeal:(MTDeal *)deal
{
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:deal];
[_db executeUpdateWithFormat:@"INSERT INTO t_collect_deal(deal, deal_id) VALUES(%@, %@);", data, deal.deal_id];
}
当很多控制器的形式一样的时候,写一个基类控制器,布局啊请求方式啊都一样,设置传递参数不一样即可
MJRefresh中,
[self.collectionView headerBeginRefreshing];
当headerFresh进入状态的时候回主动请求数据
AutoresizingMask
UIViewAutoresizingNone 不自动调整。
UIViewAutoresizingFlexibleLeftMargin 自动调整view与父视图左边距,以保证右边距不变
UIViewAutoresizingFlexibleWidth 自动调整view的宽度,保证左边距和右边距不变
UIViewAutoresizingFlexibleRightMargin 自动调整view与父视图右边距,以保证左边距不变
UIViewAutoresizingFlexibleTopMargin 自动调整view与父视图上边距,以保证下边距不变
UIViewAutoresizingFlexibleHeight 自动调整view的高度,以保证上边距和下边距不变
UIViewAutoresizingFlexibleBottomMargin 自动调整view与父视图下边距,以保证上边距不变
当导航栏的几个按钮UIBarbutton的间距太小时,设置这些item的宽度大一点,图片还是居中,这样就可以了
[self addChildViewController:citySearchResult]
[self.view addSubview:citySearchResult.view]
/**
* 2.使用谓词过滤器
// 谓词\过滤器:能利用一定的条件从一个数组中过滤出想要的数据
*/
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name contains %@ or pinYin contains %@ or pinYinHead contains %@", searchText, searchText, searchText];
self.resultCities = [[MTMetaTool cities] filteredArrayUsingPredicate:predicate];
[self.tableView reloadData];
假如说一个控制器是present出来的,那么他也是要自己dismiss掉,[self dismiss...];是自己dismiss,而不是把你present出来的那个