最近一直在忙項(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)整乐严。可是寫(xiě)完之后發(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)單寫(xiě)了一下磕诊,效果如圖:
寫(xiě)的過(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í)×律悖現(xiàn)在也把這塊給抽出來(lái)了徒河,效果如圖:
實(shí)現(xiàn)思路就是先寫(xiě)了個(gè)NSString+Extension
的分類系馆,然后把后臺(tái)返回的結(jié)束時(shí)間轉(zhuǎn)化為倒計(jì)時(shí)一共的時(shí)間送漠。然后用GCD
寫(xiě)個(gè)一秒鐘的倒計(jì)時(shí)。每1秒鐘給cell
上的UILable
賦值一次由蘑。雖然性能不會(huì)很好闽寡,但是能力有限,想不到更好的方式了尼酿。有其他寫(xiě)法的童鞋爷狈,也請(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]];
}
}];
}