addObject:和addObjectsFromArray:的區別
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];
服務器分頁的做法
服務器數據庫的數據 = @[23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10]
第1頁數據 == @[20, 19, 18, 17, 16]
做法1:
發送page參數 : page=2
第2頁數據 == @[18, 17, 16, 15, 14]
做法2:
發送maxid參數 : maxid=16
第2頁數據 == @[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)];
// 關閉NSURLSession + 取消所有請求
// NSURLSession一旦被關閉了, 就不能再發請求
[self.manager invalidateSessionCancelingTasks:YES];
// 注意: 一個請求任務被取消了(cancel), 會自動調用AFN請求的failure這個block, block中傳入error參數的code是NSURLErrorCancelled
UIAlertController
UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[controller addAction:[UIAlertAction actionWithTitle:@"收藏" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"點擊了[收藏]按鈕");
}]];
[controller addAction:[UIAlertAction actionWithTitle:@"舉報" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"點擊了[舉報]按鈕");
}]];
[controller addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"點擊了[取消]按鈕");
}]];
// [controller addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
// textField.textColor = [UIColor redColor];
// }];
[self.window.rootViewController presentViewController:controller animated:YES completion:nil];