Cascade interface (recommended Interface) construction principle and interface construction

Source: Internet
Author: User

Cascade interface (recommended Interface) construction principle and interface construction

 

 


I. Overall Layout

1. for project requirements, click cell on the left and cell data on the right. 2. it is troublesome to set up 2.1 on the interface and hand it over to two controllers for management. To click one controller, You need to notify another controller. 2. 2. Therefore, it is better to hand it over to a controller for management. 2.3 it is better to build it with xib, and put a tableView on each left and right. 3. in the development sequence, first tableView on the left and then right, because the data on the right is changed based on the data on the left. build the tableView interface on the left 1. the left-side indicator of the custom cell uses label 2 in the middle of a view. set two tableviews of the data source and set the same controller as the data source and proxy. when implementing this method, you must first determine the type of tableView. request data, View Interface Documentation 4. dictionary to model 5. show data 6. the operation found that the top of one tableView was blocked, and the other was not blocked. Why? By default, apple only sets an additional scroll area for the scrollView on the interface. You only need to cancel the additional scroll area set automatically and set it manually. 7. how can we select cell to display the cell Indicator 7.1? When the monitor cell is selected, the indicator is displayed as 7.2 but the monitor is also deselected. How can I hide the Indicator 7.3 and listen to a cell selected at the same time and deselect the other cell? Cell itself has a way to listen simultaneously
1 // call time: it is called when a cell is selected and 2-(void) setSelected :( BOOL) selected animated :( BOOL) is called when a cell is deselected) animated

 

7.4 cell does not need to be selected
1     self.selectionStyle = UITableViewCellSelectionStyleNone;

 

8. when you click cell on the left, send a request to the cell on the left of the tableView data listener on the right, send a network request, and request data on the right. build the tableView interface on the right 1. xib can also be reused. When the xib of the two interfaces is the same, the same xib can be used, as long as different models are passed to the xib. right tableView business logic 3. click cell on the left to send a network request and request data on the right. request data. See Interface documentation 4.1. We found that the category_id parameter needs to load the data on the right according to the id returned by the server on the left. Therefore, we need to add an id attribute 4.2 Reuse Model to the tableView model on the left, and the model can also be reused. We only need to add the attribute that requires data to the original model. display Data. Click cell on the left and the corresponding data is displayed on the right. overall Data Optimization 1. the first cell on the left is selected by default.
1 - (void)selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
2. By default, 0th cells are selected. Where can I write them? 2.1 written in viewDidLoad? No. At this time, no data 2.2 has to be written into the data load successfully, and the code is refreshed after the table is refreshed:
1 [self. categoryTableView reloadData]; 2 // 0th cell3 NSIndexPath * indexPath = [NSIndexPath indexPathForRow: 0 inSection: 0] by default; 4 [self. categoryTableView selectRowAtIndexPath: indexPath animated: YES scrollPosition: UITableViewScrollPositionNone];

 

3. manually select the 0th cells on the left and find that the data on the right is not refreshed by 3.1. Why? Because-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) The indexPath method must be manually clicked by the cell to trigger 3.2. How can this problem be solved? Call this method by yourself and write it after the first cell is selected by default.
1  [self tableView:self.categoryTableView didSelectRowAtIndexPath:indexPath];
4. Data Optimization 4.1 Each time you click the cell on the left, and the cell on the right needs to send a request to obtain data. The consumption performance is 4.2. If it is loaded once, it will be saved and no load will be needed next time. 4.3 Where can I save it? In the user groups saved to the corresponding classification model, define a group of users in the model of the classification tableView, save the data of tableView on the right corresponding to the cell on the left. 4.4 how do I get a set of models corresponding to the cell on the left? When requesting data on the right, the cell on the left must be selected. by recording the model corresponding to the selected cell, we can get this model 4.5 in the method of selecting the cell on the left, first, determine whether the user array in the model (the data array on the right) has a value. If there is a value, refresh the table directly, and then return. If no network request is sent, the network request is sent, after the request is successful, save the data, refresh the table, and display data 5. pull up/down refresh 1. the tableView on the right of the project needs to be pulled up/down and refreshed. 2. how can I achieve up/down refresh? Use the MJRefresh framework 3. pull down and refresh, load the latest data directly, and overwrite the original data. We used to directly use the array in the model to overwrite the original data, so there is no need to remove the original data. 4. pull-up refresh business logic 4.1 pull-up refresh, more data needs to be loaded, how to load more data? A parameter (page or ID) is required to obtain more data. The page server will return this parameter. We need to record it. Where is the record? It should be recorded in the tableView model on the left. When you request more data, you can retrieve this parameter from the model and send the 4.3 drop-down request for Refresh, to restore the page parameter, reset the page to 1. Otherwise, the data of other page numbers will be loaded to the drop-down list. When the value data is 4.4 out of order, more data will be loaded successfully, we need to refresh page + 1, because the recorded page will be passed as the next request parameter. Note: as long as the data is requested and the request is successful, refresh the page + 1 4.5, when processing and refreshing data, how can we display the original data and newly loaded data together with 4.6? Use an array to store more loaded data and add the elements in this array to the original data array 4.7. How can I add the elements in an array to another array? Through-(void) addObject :( ObjectType) anObject; method? No. This method adds the entire array as one element to another array [_ selectCategoryItem. users addObject: users]; 4. 8. Which method does it use?
1    - (void)addObjectsFromArray:(NSArray<ObjectType> *)otherArray;
This method will retrieve every element in the array and add it to another array. pull up refresh details processing 5.1 how to hide the pull up refresh control 5.2 when there is no more data? What are the hidden conditions for setting the hidden property self. userTableView. mj_footer.hidden 5.3 In the control? You need to determine the current user group. Is there more than 5.4 users? How can this problem be determined? The data returned by the server has a total_page attribute. If the current page is> = total_page, there will be no more data. 5.5 The total_page attribute needs to be saved. Where can this attribute be saved? Saved to the tableView model on the left. After each successful request, the total_page attribute is saved to the corresponding user group. 5.6 When refreshing the table, the current page attribute is the value of the current page number + 1. Therefore, the conditions for setting up pull and refresh are: page> total_page 5.7 where to write the hidden code? After the refresh table is written, the MJ refresh framework automatically determines whether the data is hidden after each refresh. It must be set after the refresh method. 5.8 each time you click the cell on the left, you also need to determine whether to hide the pull and refresh controls. Why? There may be only one page of data. If you don't judge it, the refresh control will be displayed. When you refresh the control, no more data source code will be available.
1-(void) viewDidLoad {2 [super viewDidLoad]; 3 4 self. title = @ "Recommended follow"; 5 self. automaticallyAdjustsScrollViewInsets = NO; 6 _ categoryTableView. contentInset = UIEdgeInsetsMake (64, 0, 0, 0); 7 _ userTableView. contentInset = custom (64, 0, 0, 0); 8 // type tableView register cell 9 [_ categoryTableView registerNib: [UINib nibWithNibName: @ "XMGCategoryCell" bundle: nil] forCellReuseIdentifier: categoryID]; 10 // user tableView registers cell 11 [_ userTableView registerNib: [UINib nibWithNibName: @ "XMGSubTagCell" bundle: nil] forCellReuseIdentifier: userID]; 12 // request category data 13 [self loadCategoryData]; 14 // Add up/down refresh 15 [self setupRefreshView]; 16} 17-(void) setupRefreshView 18 {19 // pull-down refresh 20 // when the user is relaxed and the pull-down refresh is fully displayed, the pull-down refresh 21 MJRefreshNormalHeader * header = [MJRefreshNormalHeader failed: @ selector (loadNewUserData)]; 22 header. automaticallyChangeAlpha = YES; 23 self. userTableView. mj_header = header; 24 25 // pull up refresh 26 MJRefreshAutoNormalFooter * footer = [empty footerWithRefreshingTarget: self refreshingAction: @ selector (loadMoreUserData)]; 27 footer. automaticallyHidden = YES; 28 self. userTableView. mj_footer = footer; 29} 30 31-(void) loadCategoryData 32 {33 AFHTTPSessionManager * mgr = [AFHTTPSessionManager xmg_manager]; 34 35 NSMutableDictionary * parameters = [NSMutableDictionary dictionary] 36 parameters [@ "a"] = @ "category"; 37 parameters [@ "c"] = @ "subscribe"; 38 39 [mgr GET: XMGBaseUrl parameters: parameters progress: nil success: ^ (NSURLSessionDataTask * _ Nonnull task, NSDictionary * _ Nullable responseObject) {40 NSArray * dictArr = responseObject [@ "list"]; 41 42 _ categorys = [XMGCategoryItem category: dictArr]; 43 44 [self. categoryTableView reloadData]; 45 46 // 0th cell 47 NSIndexPath * indexPath = [NSIndexPath indexPathForRow: 0 inSection: 0] by default; 48 [self. categoryTableView selectRowAtIndexPath: indexPath animated: YES scrollPosition: UITableViewScrollPositionNone]; 49 50 [self tableView: self. categoryTableView didSelectRowAtIndexPath: indexPath]; 51 52} failure: ^ (NSURLSessionDataTask * _ Nullable task, NSError * _ Nonnull error) {53}]; 54} 55 56-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section 57 {58 if (tableView ==_ categoryTableView) {// Display category TableView 59 return _ categorys. count; 60} 61 return _ selectCategoryItem. users. count; 62} 63 64-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath 65 {66 if (tableView = _ categoryTableView) {// Display category TableView 67 XMGCategoryCell * cell = [tableView dequeueReusableCellWithIdentifier: categoryID]; 68 cell. item = _ categorys [indexPath. row]; 69 return cell; 70} 71 XMGSubTagCell * cell = [tableView dequeueReusableCellWithIdentifier: userID]; 72 cell. user = _ selectCategoryItem. users [indexPath. row]; 73 return cell; 74} 75 76-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath 77 {78 if (tableView = _ categoryTableView) {79 return 44; 80} 81 return 60 + 1; 82} 83 // click cell to call 84 // You must manually click cell to trigger 85-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath 86 {87 if (tableView = _ categoryTableView) {88 // record the selected classification model 89 _ selectCategoryItem = _ categorys [indexPath. row]; 90 // click cell 91 // determine whether there is any data before 92 if (_ selectCategoryItem. users. count) {93 [self. userTableView reloadData]; 94 self. userTableView. mj_footer.hidden = _ selectCategoryItem. page> _ selectCategoryItem. total_page; 95 return; 96} 97 // request user data on the right 98 [self loadNewUserData]; 99} 100} 101 102 // when no more data exists, hide the pull-up refresh control 103 // determine whether the current user group has more user groups 104 // load more user data 105-(void) loadMoreUserData106 {107 [self. mgr. tasks makeObjectsPerformSelector: @ selector (cancel)]; 108 109 NSMutableDictionary * parameters = [NSMutableDictionary dictionary]; 110 parameters [@ "a"] = @ "list "; 111 parameters [@ "c"] = @ "subscribe"; 112 parameters [@ "category_id"] = _ selectCategoryItem. id; 113 parameters [@ "page"] = @ (_ selectCategoryItem. page); 114 115 [self. mgr GET: XMGBaseUrl parameters: parameters progress: nil success: ^ (NSURLSessionDataTask * _ Nonnull task, NSDictionary * _ Nullable responseObject) {116 117 [self. userTableView. mj_footer endRefreshing]; 118 119 _ selectCategoryItem. page ++; 120 NSArray * dictArr = responseObject [@ "list"]; 121 122 NSArray * users = [XMGUserItem mj_objectArrayWithKeyValuesArray: dictArr]; 123 124 // retrieve all elements in the array, add to the new array 125 // [_ selectCategoryItem. users addObject: users]; 126 [_ selectCategoryItem. users addObjectsFromArray: users]; 127 128 [self. userTableView reloadData]; 129 130 // controls whether the pull control is displayed. It must be 131 self after reloadData. userTableView. mj_footer.hidden = _ selectCategoryItem. page> _ selectCategoryItem. total_page; 132} failure: ^ (NSURLSessionDataTask * _ Nullable task, NSError * _ Nonnull error) {133}]; 134} 135 136 // load and update user data 137-(void) loadNewUserData138 {139 _ selectCategoryItem. page = 1; 140 [self. mgr. tasks makeObjectsPerformSelector: @ selector (cancel)]; 141 142 NSMutableDictionary * parameters = [NSMutableDictionary dictionary]; 143 parameters [@ "a"] = @ "list "; 144 parameters [@ "c"] = @ "subscribe"; 145 parameters [@ "category_id"] = _ selectCategoryItem. id; 146 147 [self. mgr GET: XMGBaseUrl parameters: parameters progress: nil success: ^ (NSURLSessionDataTask * _ Nonnull task, NSDictionary * _ Nullable responseObject) {148 149 _ selectCategoryItem. page ++; 150 151 // record the total number of pages of the current category: 152 _ selectCategoryItem. total_page = [responseObject [@ "total_page"] integerValue]; 153 154 // end refresh 155 [self. userTableView. mj_header endRefreshing]; 156 157 NSArray * dictArr = responseObject [@ "list"]; 158 159 _ selectCategoryItem. users = [XMGUserItem mj_objectArrayWithKeyValuesArray: dictArr]; 160 161 [self. userTableView reloadData]; 162 163 self. userTableView. mj_footer.hidden = _ selectCategoryItem. page> _ selectCategoryItem. total_page; 164 165} failure: ^ (NSURLSessionDataTask * _ Nullable task, NSError * _ Nonnull error) {166}]; 167}

I recommend it if you like it, haha.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.