0

I have quite a complex setup, and am looking for advice in how to structure my code. What I'm trying to do is something similar to twitter when you press one of a users images and can swipe through them. This is what I have at the moment:

  • A UIViewController subclass that gathers data from a server, and passes it to a UITableViewController subclass through a variable called theData
  • This UITableViewController subclass also gathers more data as the users scrolls to the bottom of the table view and appends it to theData (i.e. uses pagination). This UITableViewController subclass is reused throughout the app so that data from a different source can be passed to it.
  • When a user clicks on a UITableViewCell, a UIWindow is created which has a UIPageViewController inside it. The window uses the UITableViewController as a delegate to access theData, and passes the theData from the delegate to the UIPageViewController in a variable called pageData
  • Each page of the UIPageViewController is a UIViewController that loads images from the pageData

The next stage is to do pagination as the user swipes to the end of the pageData in the UIPageViewController. However I don't think my code is structured well enough to reuse the pagination code from the UITableViewController. Please could someone give me advice on how to improve this code structure?

Thank you

EDIT

The UIViewController in the first bullet point does more than just downloading data (it has other views within it).

I use a UIWindow to encapsulate the UIPageViewController because I want it to expand from the frame of the UITableViewCell and "take over" the full screen - covering the status bar.

4

1 回答 1

0

我的建议是创建可用于与服务器通信的简单服务。你不需要 View 控制器。

此外,您可以创建静态方法,theData无需将其传递给整个应用程序。

关于滑动,您可以将 3 个用户放在一个数组中,并对应滚动,加载额外的用户,并释放不需要的用户。这将帮助您使用内存(如果用户刷过 50 个或更多用户)。

而不是UIWindow,创建简单的从UITableViewController到 DetailView,或者在你的情况下,UIPageViewController

于 2015-05-26T13:17:13.740 回答