最近一直在忙項(xiàng)目,遇到了個(gè)下拉刷新的問(wèn)題想提出個(gè)疑問(wèn),還請(qǐng)知情的同學(xué)不吝賜教。順便再放出這段時(shí)間忙項(xiàng)目時(shí)候的倆小demo。
Demo No.1
要實(shí)現(xiàn)的下拉刷新效果是這樣的:

我的思路是這樣的。使用MJ大大的框架自定義一個(gè)Header然后根據(jù)MJRefreshState的各種狀態(tài)進(jìn)行header界面的調(diào)整??墒菍懲曛蟀l(fā)現(xiàn)當(dāng)header比較高的時(shí)候MJRefreshStatePulling這個(gè)手指松開(kāi)就可以進(jìn)行刷新的狀態(tài)監(jiān)測(cè)不到。目前只實(shí)現(xiàn)了這樣的效果


Demo已放在Github,希望知道的同學(xué),給解惑一下。在下感激不盡!謝謝。
Demo No.2
由于公司項(xiàng)目是電商,收獲地址這塊就用的是三級(jí)城市列表。因此就從項(xiàng)目中摘了出來(lái),簡(jiǎn)單寫了一下,效果如圖:

寫的過(guò)程中,比較坑的是添加收貨地址時(shí)候后臺(tái)告訴我要傳省、市、區(qū)(縣)對(duì)應(yīng)的ID,并且收獲地址列表返回?cái)?shù)據(jù)是對(duì)應(yīng)的ID。頓時(shí)都無(wú)語(yǔ)了,強(qiáng)烈要求他在列表里直接返回對(duì)應(yīng)的省市區(qū)(縣)名字了。不然三個(gè)大數(shù)組,返回的上千條數(shù)據(jù),列表和詳情都轉(zhuǎn)模型,再遍歷,這要遍歷到啥時(shí)候了。。。
關(guān)鍵點(diǎn)是顯示到界面時(shí)候的邏輯判斷,也就是取數(shù)據(jù)的這一塊。。。
#pragma mark - 點(diǎn)擊確定按鈕事件
/**
點(diǎn)擊確定按鈕事件
@param sender sender
*/
- (void)completionButtonAction:(UIButton *)sender
{
NSString *provinceName = @"";
NSString *cityName = @"";
NSString *regtionName = @"";
NSInteger _provinceID = 0;
NSInteger _cityID = 0;
NSInteger _regtionID = 0;
HPAddAddressPickerModel *pickerModel;
HPAddAddressCityModel *cityModel;
HPAddAddressRegionModel *regtionModel;
if (_provinceArray.count > 0) {
if (_firstCurrentIndex > 0) {
if (_firstCurrentIndex - 1 < _provinceArray.count) {
pickerModel = _provinceArray[_firstCurrentIndex - 1];
//獲取省
provinceName = pickerModel.name;
_provinceID = pickerModel.provinceID;
}
}
}
if (_cityArray.count > 0) {
if (_secondCurrentIndex > 0) {
if (_secondCurrentIndex - 1 < _cityArray.count) {
cityModel = _cityArray[_secondCurrentIndex - 1];
//獲取市
cityName = cityModel.name;
if (cityModel.parent_id == pickerModel.provinceID) {
_cityID = cityModel.city_id;
}
}
}
}
if (_regionArray.count > 0) {
if (_thirdCurrentIndex > 0) {
if (_thirdCurrentIndex - 1 < _regionArray.count) {
//獲取區(qū)
regtionModel = _regionArray[_thirdCurrentIndex - 1];
regtionName = regtionModel.name;
if (regtionModel.parent_id == cityModel.city_id) {
_regtionID = regtionModel.region_id;
}
}
}
}
NSLog(@"省%ld 市%ld 區(qū)%ld",_provinceID,_cityID,_regtionID);
if (_provinceID == 0) {
// [STTextHudTool showText:@"請(qǐng)選擇正確的省份" withSecond:1];
return;
}else if (_cityID == 0) {
// [STTextHudTool showText:@"請(qǐng)選擇正確的城市" withSecond:1];
return;
}else if (_regtionID == 0){
// [STTextHudTool showText:@"請(qǐng)選擇正確的區(qū)(縣)" withSecond:1];
return;
}
NSDictionary *params = @{
@"province": @{
@"provinceName":provinceName,
@"provinceID":kStringIntegerFormat(_provinceID)
},
@"city": @{
@"cityName":cityName,
@"cityID":kStringIntegerFormat(_cityID)
},
@"regition":@{
@"regtionName":regtionName,
@"regitionID":kStringIntegerFormat(_regtionID)
},
};
if (_completion) {
_completion(params);
}
}
Demo No.3
公司項(xiàng)目首頁(yè)搶購(gòu)商品cell上需要根據(jù)后臺(tái)返回的結(jié)束時(shí)間加一個(gè)倒計(jì)時(shí)?,F(xiàn)在也把這塊給抽出來(lái)了,效果如圖:

實(shí)現(xiàn)思路就是先寫了個(gè)NSString+Extension的分類,然后把后臺(tái)返回的結(jié)束時(shí)間轉(zhuǎn)化為倒計(jì)時(shí)一共的時(shí)間。然后用GCD寫個(gè)一秒鐘的倒計(jì)時(shí)。每1秒鐘給cell上的UILable賦值一次。雖然性能不會(huì)很好,但是能力有限,想不到更好的方式了。有其他寫法的童鞋,也請(qǐng)多多指教~
關(guān)鍵代碼在這里:
- (void)viewDidLoad {
[super viewDidLoad];
WS(weakSelf);
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuseIdentifier"];
[self.homePageViewModel countDownWithPER_SECBlock:^{
[weakSelf updateTimeInVisibleCells];
}];
}
#pragma mark - Custom Method
- (void)updateTimeInVisibleCells
{
//遍歷當(dāng)前 屏幕可見(jiàn)cell,對(duì)cell上的倒計(jì)時(shí)一秒鐘賦值一次
[self.tableView.visibleCells enumerateObjectsUsingBlock:^(__kindof UITableViewCell * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ( [obj isKindOfClass:[UITableViewCell class]]) {
// [NSString stringToCurtDownString:string] 這個(gè)是分類方法
obj.textLabel.text = [NSString stringToCurtDownString:self.homePageViewModel.rushArray[obj.tag]];
}
}];
}