我正在使用帶滾動列表的UItableview。現在我有默認的「加載更多」按鈕,一次加載10個對象。它破壞了界面。有關如何定製它的任何想法? A試了幾件事,但我們沒有運氣。由於在行列表中自定義iOS「加載更多」按鈕
0
A
回答
3
嘗試實施這種方法解析提供用於自定義「加載更多」細胞:
// Override to customize the look of the cell that allows the user to load the next page of objects.
// The default implementation is a UITableViewCellStyleDefault cell with simple labels.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForNextPageAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"NextPage";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = @"Load more...";
return cell;
}
0
那麼有沒有什麼可以在定製方面與解析控制器做。此外,該控制器的動畫似乎有點笨拙。在使用具有最新IO 9的組件時,我也遇到了一堆內存錯誤。
出於同樣的原因,我用以下替換了現有的Parse控制器。與標準的PARSE控制器相比,讓我對動畫和設計有了更多的控制權。
如果你想扭轉的tableview的順序,看起來像一個信使的應用程序,請看看here
添加全局變量
var objects = [PFObject(className: "Posts")]
var lockScrollSensor = false
let objectsPerPage = 10
添加到viewDidLoad中
//blank screen
let blankView = UIView(frame: CGRectMake(0, 0, self.tableView.frame.size.width, self.tableView.frame.size.height - 60))
blankView.tag = 101
blankView.backgroundColor = customColorYellow()
self.view.addSubview(blankView)
self.tableView.backgroundColor = customColorYellow()
// load tableview
tableViewFirstLoad()
Detect t他的tableview滾動的位置移動到呼叫刷新或下一頁
override func scrollViewDidScroll(scrollView: UIScrollView) {
let scrollViewHeight = scrollView.frame.size.height;
let scrollContentSizeHeight = scrollView.contentSize.height;
let scrollOffset = scrollView.contentOffset.y;
// refresh - touch top
if (scrollOffset < -60)
{
if lockScrollSensor == false {
// stop method from non stop calling
lockScrollSensor = true
// loader
let spinningActivity = MBProgressHUD.showHUDAddedTo(self.parentViewController?.view, animated: true)
spinningActivity.color = UIColor.clearColor()
spinningActivity.activityIndicatorColor = customColorRed()
spinningActivity.yOffset = -Float((self.parentViewController?.view.frame.height)!/2) + 95
// call method to load more
self.tableViewRefresh({ (done) -> Void in
if done == true
{
// stop loader and free method
spinningActivity.hide(true, afterDelay: 0)
self.lockScrollSensor = false
// animate tableview
self.tableView.contentOffset.y = -60
UIView.animateWithDuration(1.5, delay: 1, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: UIViewAnimationOptions.CurveEaseIn, animations: {() -> Void in
self.tableView.contentOffset.y = 0
}, completion: nil)
}
})
}
}
// load more - touch down
else if (scrollOffset + scrollViewHeight > scrollContentSizeHeight)
{
if lockScrollSensor == false {
// stop method from non stop calling
lockScrollSensor = true
// start loader
let spinningActivity = MBProgressHUD.showHUDAddedTo(self.parentViewController?.view, animated: true)
spinningActivity.color = customColorYellow()
spinningActivity.yOffset = (Float(tableView.frame.size.height)/2)-25
// call method to load more
self.tableViewLoadMore({ (done) -> Void in
if done == true {
self.lockScrollSensor = false
spinningActivity.hide(true)
}
})
}
}
}
刷新或翻頁方法,將加載您PFObject陣列。
// first load
func tableViewFirstLoad(result: (done: Bool) -> Void){
var query = PFQuery(className: "Posts")
query = segueDataChecker()
// limit objects
query.limit = objectsPerPage
// get objects
query.findObjectsInBackgroundWithBlock { (posts: [AnyObject]?, error: NSError?) -> Void in
if error != nil
{
result(done: true)
let alertView = createDefaultAlertError(message: "\(error!.localizedDescription.capitalizedString)", actions: [UIAlertAction(title: "Ok", style: UIAlertActionStyle.Cancel, handler: nil)])
self.presentViewController(alertView, animated: true, completion: nil)
}
else
{
// clean array
self.objects.removeAll()
// populate array
for eachPost in posts!
{
if self.objects.count < self.objectsPerPage
{
self.objects.append(eachPost as! PFObject)
}
}
// reload and send back it has finished
self.tableView.reloadData()
result(done: true)
self.tableView.backgroundColor = UIColor(patternImage: UIImage(named: "pattern_clear_white.pdf")!)
// remove uiview
UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {() -> Void in
if let viewWithTag = self.view.viewWithTag(101)
{
viewWithTag.alpha = 0
}
}, completion: nil)
}
}
}
// refresh existing content
func tableViewRefresh(result: (done: Bool) -> Void){
var query = PFQuery(className: "Posts")
query = segueDataChecker()
// limit objects
query.limit = self.objects.count
// save number of objects already loaded
let actualNumberOfPosts = self.objects.count
// get objects
query.findObjectsInBackgroundWithBlock { (posts: [AnyObject]?, error: NSError?) -> Void in
if error != nil
{
result(done: true)
let alertView = createDefaultAlertError(message: "\(error!.localizedDescription.capitalizedString)", actions: [UIAlertAction(title: "Ok", style: UIAlertActionStyle.Cancel, handler: nil)])
self.presentViewController(alertView, animated: true, completion: nil)
}
else
{
// clean array
self.objects.removeAll()
// populate array with same updated objects
for eachPost in posts!
{
if self.objects.count < actualNumberOfPosts
{
self.objects.append(eachPost as! PFObject)
}
}
// reload and send back it has finished
self.tableView.reloadData()
result(done: true)
}
}
}
// load next results
func tableViewLoadMore(result: (done: Bool) -> Void){
var query = PFQuery(className: "Posts")
query = segueDataChecker()
// skip objects already loaded
query.skip = self.objects.count; // skip the first 20 results
// limit results to next page amount
query.limit = objectsPerPage
// save number of objects already loaded
let actualNumberOfPosts = self.objects.count
// get objects
query.findObjectsInBackgroundWithBlock { (posts: [AnyObject]?, error: NSError?) -> Void in
if error != nil
{
result(done: true)
let alertView = createDefaultAlertError(message: "\(error!.localizedDescription.capitalizedString)", actions: [UIAlertAction(title: "Ok", style: UIAlertActionStyle.Cancel, handler: nil)])
self.presentViewController(alertView, animated: true, completion: nil)
}
else
{
// if there anything new
if posts?.count != 0
{
// populate array with new objects
for eachPost in posts!
{
if (self.objects.count < self.objectsPerPage + actualNumberOfPosts)
{
self.objects.append(eachPost as! PFObject)
}
}
// reload and send back it has finished
self.tableView.reloadData()
result(done: true)
// slide tablview one result down
let newIndexPath = NSIndexPath(forRow: actualNumberOfPosts, inSection: 0)
self.tableView.scrollToRowAtIndexPath(newIndexPath , atScrollPosition: UITableViewScrollPosition.None, animated: true)
}
// if there is nothing new
else
{
result(done: true)
}
}
}
}
相關問題
- 1. iOS QuickLook添加自定義按鈕
- 2. 在IOS中自定義後退按鈕
- 3. Ajax加載更多按鈕
- 4. jQuery加載更多按鈕
- 5. instagram加載更多按鈕
- 6. 在acumatica中添加自定義按鈕
- 7. 「在多個表格中加載更多」分頁按鈕。 Django
- 8. 在自定義列表的末尾添加一個按鈕
- 9. 如何將自定義按鈕添加到管理列表中?
- 10. android自定義列表視圖與自定義單選按鈕
- 11. 自定義表單按鈕
- 12. android自定義列表查看選定的行按鈕點擊
- 13. 自定義列表片段列表項每當我按下按鈕時增加
- 14. Animate自定義按鈕iOS Swift
- 15. 自定義iOS浮動按鈕
- 16. 添加自定義按鈕的UITabBarController(中間添加按鈕)
- 17. 加載更多的按鈕,將加載更多的帖子
- 18. IOS中的自定義後退按鈕的奇怪行爲
- 19. iOS:在自定義導航欄中定位導航欄按鈕
- 20. 將自定義按鈕添加到Sharepoint 2013列表項目
- 21. Sapui5:如何將按鈕列表添加到自定義控件?
- 22. 將自定義按鈕添加到jquery下拉列表
- 23. Outlook 2003工具欄自定義:添加/編輯按鈕列表
- 24. 在jqGrid的行中添加一個自定義按鈕?
- 25. 在SharePoint列表中自定義「Like」按鈕
- 26. 如何使用按鈕實現自定義列表視圖行?
- 27. 使用JavaScript/jQuery從數組填充列表並在「加載更多」按鈕上加載更多項目單擊?
- 28. 自定義添加視圖 - 將下拉列表更改爲單選按鈕
- 29. 將動畫SWF加載到自定義Flex(火花)按鈕中
- 30. 如何在PropertyGrid自定義集合編輯器中的「添加」按鈕下拉列表中自定義名稱
你也碰巧知道如何改變NSString的高度* CellIdentifier = @「NextPage」; – user3615707 2014-09-05 10:33:12
@ user3615707這只是標識符,不在任何位置的單元格 – Jacob 2014-09-05 11:04:59
好的。所以不可能改變那個加載更多單元的大小? – user3615707 2014-09-05 12:05:47