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];