iOS 的一點小記載(七)

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

服務器分頁的做法

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


第1頁數據 == @[20, 19, 18, 17, 16]

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

做法2:
發(fā)送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一旦被關閉了, 就不能再發(fā)請求
[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];
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容