iOS 的一點(diǎn)小記載(七)

addObject:和addObjectsFromArray:的區(qū)別

self.topics = @[20, 19, 18]
moreTopics = @[17, 16, 15]

self.topics = @[20, 19, 18, @[17, 16, 15]]
[self.topics addObject:moreTopics];

self.topics = @[20, 19, 18, 17, 16, 15]
[self.topics addObjectsFromArray:moreTopics];

服務(wù)器分頁的做法

服務(wù)器數(shù)據(jù)庫的數(shù)據(jù) = @[23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10]


第1頁數(shù)據(jù) == @[20, 19, 18, 17, 16]

做法1:
發(fā)送page參數(shù) : page=2
第2頁數(shù)據(jù) == @[18, 17, 16, 15, 14]

做法2:
發(fā)送maxid參數(shù) : maxid=16
第2頁數(shù)據(jù) == @[15, 14, 13, 12, 11]

集成MJRefresh

self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewTopics)];
[self.tableView.mj_header beginRefreshing];

self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreTopics)];

利用AFN取消請求

// 取消所有請求
for (NSURLSessionTask *task in self.manager.tasks) {
    [task cancel];
}

// 取消所有請求
[self.manager.tasks makeObjectsPerformSelector:@selector(cancel)];

// 關(guān)閉NSURLSession + 取消所有請求
// NSURLSession一旦被關(guān)閉了, 就不能再發(fā)請求
[self.manager invalidateSessionCancelingTasks:YES];

// 注意: 一個(gè)請求任務(wù)被取消了(cancel), 會(huì)自動(dòng)調(diào)用AFN請求的failure這個(gè)block, block中傳入error參數(shù)的code是NSURLErrorCancelled

UIAlertController

UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

[controller addAction:[UIAlertAction actionWithTitle:@"收藏" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"點(diǎn)擊了[收藏]按鈕");
}]];

[controller addAction:[UIAlertAction actionWithTitle:@"舉報(bào)" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"點(diǎn)擊了[舉報(bào)]按鈕");
}]];

[controller addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"點(diǎn)擊了[取消]按鈕");
}]];

//    [controller addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
//        textField.textColor = [UIColor redColor];
//    }];

[self.window.rootViewController presentViewController:controller animated:YES completion:nil];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容