IOS diary app creation process (Objective-C), iosobjective-c
1. Framework I use Realm as the database framework, and SDAutoLayout for adaptation. It doesn't matter. The two frameworks are simple. 2. When the log is set logically, three data records are recorded, including the title, content, and the time when the diary is written. This time is accurate to seconds, which is equivalent to the primary key of the database. You can click the previously written diary item to modify it. This time will also be modified. 3. Set the interface. I will paste two pictures first. You can understand it. There are not many widgets. the main interface is a list of all the diary information, and an Add button will jump to the diary page! [Write picture description here] (http://img.blog.csdn.net/20171218141412941? Watermark/2/text/plain =/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA =/dissolve/70/gravity/SouthEast, two textviews are the subject, and the three buttons are respectively responsible for saving, canceling, and deleting the functions, the delete button is displayed only when you click the information list of a diary .! [Write picture description here] (http://img.blog.csdn.net/20171218141446101? Watermark/2/text/plain =/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA =/dissolve/70/gravity/SouthEast) 4. the logic code ''' of the main interface of the subject logic code /// MainViewController. m // Note /// Created by shanreal-iOS on. // Copyright 2017 shanreal. longZhenHao. all rights reserved. // # import "MainViewController. h "# import" MainView. h "# import" MainModel. h "# import" MainTableViewCell. h "# import" DetailViewController. h "# import" NoteBean. h "@ interface MainViewController () <UITableViewDelegate, UITableViewDataSource> @ property (nonatomic, strong) MainView * mainview; @ property (nonatomic, strong) MainModel * model; @ property (nonatomic, strong) NSMutableArray * dataArray; @ end @ implementation MainViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. self. navigationController. navigationBar. hidden = YES; self. navigationController. navigationBar. barStyle = UIBarStyleBlack; self. mainview = [[MainView alloc] initWithFrame: self. view. frame]; [self. mainview viewInit]; [self. mainview. tableview_main setSeparatorStyle: UITableViewCellSeparatorStyleNone]; self. mainview. tableview_main.bounces = NO; self. mainview. tableview_main.delegate = self; self. mainview. tableview_main.dataSource = self; [self. mainview. btn_add addTarget: self action: @ selector (addAction) forControlEvents: UIControlEventTouchUpInside]; [self. view addSubview: self. mainview];/* RLMResults * delete = [NoteBean allObjects]; RLMRealm * realm = [RLMRealm defaultRealm]; [realm transactionWithBlock: ^ {for (NoteBean * bean in delete) {[realm deleteObject: bean] ;}}]; */NSString * a = [TimeStampUtil getCurrentTimeStemp]; NSLog (a);}-(void) viewWillAppear :( BOOL) animated {[super viewWillAppear: animated]; self. dataArray = [NSMutableArray new]; RLMResults * data = [[NoteBean allObjects] sortedResultsUsingKeyPath: @ "date" ascending: NO]; [[RLMRealm defaultRealm] transactionWithBlock: ^ {for (NoteBean * bean in data) {[self. dataArray addObject: bean] ;}}]; [self. mainview. tableview_main reloadData]; NSLog (@ "% d", self. dataArray. count);}-(void) addAction {DetailViewController * vc = [[DetailViewController alloc] init]; vc. sort = 0; [self. navigationController pushViewController: vc animated: YES];}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} # pragma mark-UITableViewDataSource-(NSInteger) values :( UITableView *) theTableView {return 1;}-(NSInteger) tableView :( UITableView *) theTableView numberOfRowsInSection :( NSInteger) section {return self. dataArray. count;}-(UITableViewCell *) tableView :( UITableView *) theTableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {NSString * handle = [NSString stringWithFormat: @ "MainTableViewCell % ld ", [indexPath section], [indexPath row]; MainTableViewCell * cell = (MainTableViewCell *) [theTableView dequeueReusableCellWithIdentifier: cellIdentifier]; if (cell = nil) {cell = [[MainTableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: cellIdentifier];} NoteBean * bean = self. dataArray [indexPath. row]; cell. label_title.text = bean. title; cell. label_date.text = bean. date; return cell;}-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {return 50 * MY;} # pragma mark-UITableViewDelegate-(void) tableView :( UITableView *) theTableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {[theTableView deselectRowAtIndexPath: indexPath animated: YES]; NSLog (@ "selected % ld row", indexPath. row); DetailViewController * vc = [[DetailViewController alloc] init]; vc. sort = 1; vc. date = (NoteBean *) self. dataArray [indexPath. row]). date; vc. title = (NoteBean *) self. dataArray [indexPath. row]). title; vc. content = (NoteBean *) self. dataArray [indexPath. row]). content; [self. navigationController pushViewController: vc animated: YES];} @ end '''logic code of the date writing interface ''' # import <UIKit/UIKit. h> # import "DetailView. h "# import" DetailModel. h "# import" NoteBean. h "@ interface DetailViewController: UIViewController @ property (nonatomic, assign) int sort; @ property (nonatomic, strong) NSString * date; @ property (nonatomic, strong) NSString * title; @ property (nonatomic, strong) NSString * content; @ end // DetailViewController. m // Note /// Created by shanreal-iOS on. // Copyright 2017 shanreal. longZhenHao. all rights reserved. // # import "DetailViewController. h "@ interface DetailViewController () @ property (nonatomic, strong) DetailView * detailview; @ end @ implementation DetailViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. self. navigationController. navigationBar. hidden = YES; self. navigationController. navigationBar. barStyle = UIBarStyleBlack; self. detailview = [[DetailView alloc] initWithFrame: self. view. frame]; [self. detailview viewInit]; [self. detailview. btn_save addTarget: self action: @ selector (saveAction) forControlEvents: UIControlEventTouchUpInside]; [self. detailview. btn_back addTarget: self action: @ selector (cancelAction) forControlEvents: UIControlEventTouchUpInside]; [self. detailview. btn_delete addTarget: self action: @ selector (deleteAction) forControlEvents: UIControlEventTouchUpInside]; self. detailview. tf_title.text = self. title; self. detailview. TV _content.text = self. content; [self. view addSubview: self. detailview]; if (self. sort = 1) self. detailview. btn_delete.hidden = NO;}-(void) viewWillAppear :( BOOL) animated {[super viewWillAppear: animated];}-(void) didreceivemorywarning {[super ready]; // Dispose of any resources that can be recreated .} -(void) deleteAction {NSLog (@ "delete"); NSPredicate * pred = [NSPredicate predicateWithFormat: @ "date = % @", self. date]; RLMResults <NoteBean *> * beans = [NoteBean objectsWithPredicate: pred]; RLMRealm * realm = [RLMRealm defaultRealm]; [realm transactionWithBlock: ^ {NoteBean * bean = [beans objectAtIndex: 0]; [realm deleteObject: bean] ;}]; [ShowToastView showToastView: self. view WithMessage: @ "deleted successfully"]; [self defined mselector: @ selector (cancelAction) withObject: nil afterDelay: 2];}-(void) saveAction {NSString * title = self. detailview. tf_title.text; NSString * content = self. detailview. TV _content.text; if ([title isw.tostring: @ ""] | title = NULL) {[ShowToastView showToastView: self. view WithMessage: @ "title not written"]; return;} if ([content isinclutostring: @ ""] | content = NULL) {[ShowToastView showToastView: self. view WithMessage: @ "content not written"]; return;} NSLog (@ "save % @", title, content); if (self. sort = 0) {NoteBean * bean = [[NoteBean alloc] init]; bean. date = [TimeStampUtil getCurrentTimeStemp]; bean. title = self. detailview. tf_title.text; bean. content = self. detailview. TV _content.text; RLMRealm * realm = [RLMRealm defaultRealm]; [realm transactionWithBlock: ^ {[realm addObject: bean];}]; [ShowToastView showToastView: self. view WithMessage: @ "saved successfully"];} else if (self. sort = 1) {NSPredicate * pred = [NSPredicate predicateWithFormat: @ "date = % @", self. date]; RLMResults <NoteBean *> * beans = [NoteBean objectsWithPredicate: pred]; [[RLMRealm defaultRealm] transactionWithBlock: ^ {NoteBean * bean = [beans objectAtIndex: 0]; bean. date = [TimeStampUtil getCurrentTimeStemp]; bean. title = self. detailview. tf_title.text; bean. content = self. detailview. TV _content.text;}]; [ShowToastView showToastView: self. view WithMessage: @ "modified successfully"];} [self defined mselector: @ selector (cancelAction) withObject: nil afterDelay: 2];}-(void) cancelAction {NSLog (@ "cancel"); [self. navigationController popViewControllerAnimated: YES];} @ end ''' finally I offered the Source Code address http://download.csdn.net/download/z979451341/10163474