我是一个新手,正在开发一个应用程序,该应用程序既显示用户从应用程序附带的集合中随机选择的俳句,又允许他/她编写俳句来添加该集合。它还将用户带到一个网页的网页视图,她/他可以从中购买俳句书籍。问题是,我已经将几乎所有的方法都放在了视图控制器中,而且我觉得好的 MVC 工作会以不同的方式划分它。以下是我的基本方法(为简洁起见,我合并了一些,省略了一些其他方法的子方法,还有 Foundation 和 UIKit 方法),并附有简要说明:
GHHaiku.m //This is a model class, or at least I think it is.
-(int)chooseNumber {
returns a random number
}
-(NSString *)haikuToShow {
uses that number to return haiku from collection
}
GHViewController.m
-(void) viewDidLoad
-(void) viewDidUnload
-(void) clearScreen {
gets rid of all UITextFields and images so that a new set of them can be created, perhaps with different parameters.
}
-(void) saveData {
saves persistent information like whether user has read the instructions
}
-(void)home {
takes user “home” from whatever screen we're in and shows next haiku
}
//--code to set up navBar and Toolbar
-(void)createNavBar:title {
creates and adds buttons to a UINavigationItem with “title” as title and adds UINavigationBar to view
}
-(void) loadToolbar {
loads toolbar at bottom of screen and adds buttons
}
//--code for instructions page
-(void) haikuInstructions {
shows instructions on screen
}
//--code for Amazon page
-(void) loadAmazon {
loads webview of haiku page at amazon.com
}
-(void) webViewDidFinishLoad:(UIWebView)
-(BOOL) webview:(UIWebView) shouldStartLoadWithRequest:(NSURLRequest) navigationType:(UIWebViewNavigationType)
-(void) connectWithURL☹NSString) andBaseURLString: (NSString)
-(BOOL) connection: (NSURLConnection) didFailWithError: (NSError)
-(void) doneWithAmazon {
takes user out of webview Amazon and shows next haiku
}
//--code for compose page
-(void) createSpaceToWrite {
sets up and shows an editable UITextView
}
-(void) userWritesHaiku {
allows user to write haiku
}
-(void) userEditsHaiku {
takes user to edit screen for haiku s/he’s already written.
-(void) userFinishedWritingHaiku {
shows action sheet once user’s done
}
-(void) deleteHaiku {
allows user to delete haiku s/he’s written
}
-(void) saveUserHaiku {
saves user haiku to documents folder
}
-(void) takeToOptOut {
allows user to opt out of sending haiku to central database
}
//--code for sharing
-(void) createImage {
creates image of haiku
}
-(void) showActionSheet {
gives user options to tweet, faceBook, or email
}
-(void) share {
allows user to tweet, email, or facebook that image
}
//--code for display page
-(IBAction)chooseDatabase: (UISegmentedControl) {
allows user to choose whether to see his/her own haiku and/or haiku that come with the application
}
-(void) fadeView {
fades the UISegmentedControl for chooseDatabase
}
-(void) nextHaiku {
shows next haiku
}
-(void) previousHaiku {
shows previous haiku
}
我不得不想象其中一些属于不同的类,但我不知道在 GHViewController 中放置什么以及保留什么。(我认为我的部分困惑是因为“视图控制器”同时包含“视图”和“控制器”,我不明白它是视图、控制器还是两者都不是......)
无论如何,我很喜欢关于我应该创建的其他类以及我应该在其中放入哪些方法的建议。