Przeglądaj źródła

1.完成Apex Mobile历史记录界面。

Pen Li 8 lat temu
rodzic
commit
eed64c9dae

+ 65 - 2
Apex Mobile/Apex Mobile.xcodeproj/project.pbxproj

@@ -7,6 +7,11 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		425CF096201EB2B500750E32 /* JLRefreshFooter.m in Sources */ = {isa = PBXBuildFile; fileRef = 425CF08C201EB2B500750E32 /* JLRefreshFooter.m */; };
+		425CF097201EB2B500750E32 /* JLRefreshHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 425CF08F201EB2B500750E32 /* JLRefreshHeader.m */; };
+		425CF098201EB2B500750E32 /* JLRefreshBasis.m in Sources */ = {isa = PBXBuildFile; fileRef = 425CF091201EB2B500750E32 /* JLRefreshBasis.m */; };
+		425CF099201EB2B500750E32 /* UIScrollView+JLRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = 425CF093201EB2B500750E32 /* UIScrollView+JLRefresh.m */; };
+		425CF09A201EB2B500750E32 /* UIView+JLExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 425CF095201EB2B500750E32 /* UIView+JLExtension.m */; };
 		42604122201C4B41002374A8 /* ShipingStatusCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 42604121201C4B41002374A8 /* ShipingStatusCell.m */; };
 		42604127201C578B002374A8 /* ShipSearchController.m in Sources */ = {isa = PBXBuildFile; fileRef = 42604126201C578B002374A8 /* ShipSearchController.m */; };
 		42604129201C57A7002374A8 /* ShipSearch.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 42604128201C57A7002374A8 /* ShipSearch.storyboard */; };
@@ -136,6 +141,16 @@
 /* End PBXContainerItemProxy section */
 
 /* Begin PBXFileReference section */
+		425CF08B201EB2B500750E32 /* JLRefreshFooter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JLRefreshFooter.h; sourceTree = "<group>"; };
+		425CF08C201EB2B500750E32 /* JLRefreshFooter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JLRefreshFooter.m; sourceTree = "<group>"; };
+		425CF08E201EB2B500750E32 /* JLRefreshHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JLRefreshHeader.h; sourceTree = "<group>"; };
+		425CF08F201EB2B500750E32 /* JLRefreshHeader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JLRefreshHeader.m; sourceTree = "<group>"; };
+		425CF090201EB2B500750E32 /* JLRefreshBasis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JLRefreshBasis.h; sourceTree = "<group>"; };
+		425CF091201EB2B500750E32 /* JLRefreshBasis.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JLRefreshBasis.m; sourceTree = "<group>"; };
+		425CF092201EB2B500750E32 /* UIScrollView+JLRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+JLRefresh.h"; sourceTree = "<group>"; };
+		425CF093201EB2B500750E32 /* UIScrollView+JLRefresh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+JLRefresh.m"; sourceTree = "<group>"; };
+		425CF094201EB2B500750E32 /* UIView+JLExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+JLExtension.h"; sourceTree = "<group>"; };
+		425CF095201EB2B500750E32 /* UIView+JLExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+JLExtension.m"; sourceTree = "<group>"; };
 		42604120201C4B41002374A8 /* ShipingStatusCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShipingStatusCell.h; sourceTree = "<group>"; };
 		42604121201C4B41002374A8 /* ShipingStatusCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ShipingStatusCell.m; sourceTree = "<group>"; };
 		42604125201C578B002374A8 /* ShipSearchController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShipSearchController.h; sourceTree = "<group>"; };
@@ -373,6 +388,49 @@
 /* End PBXFrameworksBuildPhase section */
 
 /* Begin PBXGroup section */
+		425CF088201EAF8800750E32 /* History */ = {
+			isa = PBXGroup;
+			children = (
+				715643C22019B58400B04267 /* OrderHistoryViewController.h */,
+				715643C32019B58400B04267 /* OrderHistoryViewController.m */,
+			);
+			name = History;
+			sourceTree = "<group>";
+		};
+		425CF089201EB2B500750E32 /* Refresh */ = {
+			isa = PBXGroup;
+			children = (
+				425CF08A201EB2B500750E32 /* Footer */,
+				425CF08D201EB2B500750E32 /* Header */,
+				425CF090201EB2B500750E32 /* JLRefreshBasis.h */,
+				425CF091201EB2B500750E32 /* JLRefreshBasis.m */,
+				425CF092201EB2B500750E32 /* UIScrollView+JLRefresh.h */,
+				425CF093201EB2B500750E32 /* UIScrollView+JLRefresh.m */,
+				425CF094201EB2B500750E32 /* UIView+JLExtension.h */,
+				425CF095201EB2B500750E32 /* UIView+JLExtension.m */,
+			);
+			name = Refresh;
+			path = "../../RedAnt Mobile/RedAnt Mobile/Refresh";
+			sourceTree = "<group>";
+		};
+		425CF08A201EB2B500750E32 /* Footer */ = {
+			isa = PBXGroup;
+			children = (
+				425CF08B201EB2B500750E32 /* JLRefreshFooter.h */,
+				425CF08C201EB2B500750E32 /* JLRefreshFooter.m */,
+			);
+			path = Footer;
+			sourceTree = "<group>";
+		};
+		425CF08D201EB2B500750E32 /* Header */ = {
+			isa = PBXGroup;
+			children = (
+				425CF08E201EB2B500750E32 /* JLRefreshHeader.h */,
+				425CF08F201EB2B500750E32 /* JLRefreshHeader.m */,
+			);
+			path = Header;
+			sourceTree = "<group>";
+		};
 		42604123201C53DB002374A8 /* Home */ = {
 			isa = PBXGroup;
 			children = (
@@ -427,6 +485,7 @@
 			isa = PBXGroup;
 			children = (
 				42604124201C53ED002374A8 /* ShipStatusCell */,
+				425CF088201EAF8800750E32 /* History */,
 				42604123201C53DB002374A8 /* Home */,
 				7162546E201C51DC009E3A41 /* fake data */,
 				7162546A201C3AF1009E3A41 /* readme.txt */,
@@ -435,8 +494,6 @@
 				715643BA20198A9900B04267 /* RootViewController.m */,
 				715643BC2019AA9B00B04267 /* LoginViewController.h */,
 				715643BD2019AA9B00B04267 /* LoginViewController.m */,
-				715643C22019B58400B04267 /* OrderHistoryViewController.h */,
-				715643C32019B58400B04267 /* OrderHistoryViewController.m */,
 				715643C52019BB6700B04267 /* StaticModelistViewController.h */,
 				715643C62019BB6700B04267 /* StaticModelistViewController.m */,
 				715643D4201AD2AB00B04267 /* StaticModelistViewController.xib */,
@@ -688,6 +745,7 @@
 		719EF8E618BB839F00EFFF5F /* Apex Mobile */ = {
 			isa = PBXGroup;
 			children = (
+				425CF089201EB2B500750E32 /* Refresh */,
 				715643B820198A6000B04267 /* new */,
 				71C72714191CFF11001127E0 /* message */,
 				713AA79E1917366A00B44092 /* documents */,
@@ -925,6 +983,7 @@
 				71375C8F18D96EDE00EBA026 /* TabBarController.m in Sources */,
 				71951E6F18C6A9A5005024BD /* TouchLabel.m in Sources */,
 				71DA6047190A00F600683003 /* FavoritesData.m in Sources */,
+				425CF099201EB2B500750E32 /* UIScrollView+JLRefresh.m in Sources */,
 				71A01D7C18C9AE97003307A9 /* DetailCellList.m in Sources */,
 				71DA74A618BDDD31003B46A6 /* AboutViewController.m in Sources */,
 				715643C42019B58400B04267 /* OrderHistoryViewController.m in Sources */,
@@ -950,11 +1009,13 @@
 				71CEE38A18CB749E00052C63 /* DetailPageViewController.m in Sources */,
 				71286AB618C70061001FDF43 /* NSData+Base64.m in Sources */,
 				719E7E3318C0368A003408FF /* ApexMobileDB.m in Sources */,
+				425CF096201EB2B500750E32 /* JLRefreshFooter.m in Sources */,
 				715643C12019B27500B04267 /* HomeViewController.m in Sources */,
 				715643C72019BB6700B04267 /* StaticModelistViewController.m in Sources */,
 				719E7E3018C015D0003408FF /* ApexMobileNetwork.m in Sources */,
 				719EF8F118BB839F00EFFF5F /* ApexMobileAppDelegate.m in Sources */,
 				714C39B81922FEE1004F045B /* NewsDetailViewController.m in Sources */,
+				425CF098201EB2B500750E32 /* JLRefreshBasis.m in Sources */,
 				715643CD2019BC6C00B04267 /* ToolslistViewController.m in Sources */,
 				712A301318CFEF550022E6E6 /* CustomizeFieldViewController.m in Sources */,
 				716FF7921904ED2600ED6C3D /* NewsData.m in Sources */,
@@ -965,6 +1026,7 @@
 				71BA50311908ED9100D0BD31 /* HistoryViewController.m in Sources */,
 				71A2D76218DC3895001C380A /* LineView.m in Sources */,
 				719A51B418C5A8100080C075 /* ResultViewController.m in Sources */,
+				425CF097201EB2B500750E32 /* JLRefreshHeader.m in Sources */,
 				711DC6B218C30A4800FB1749 /* TableCellEdit.m in Sources */,
 				71286AB818C70061001FDF43 /* NSString+Base64.m in Sources */,
 				71A01D8218C9BA67003307A9 /* DetailContent.m in Sources */,
@@ -980,6 +1042,7 @@
 				71286AB418C70061001FDF43 /* AESCrypt.m in Sources */,
 				713AA7A1191736E600B44092 /* DocumentsViewController.m in Sources */,
 				716FF7951904FBC600ED6C3D /* NewsTableViewCell.m in Sources */,
+				425CF09A201EB2B500750E32 /* UIView+JLExtension.m in Sources */,
 				71A01D7918C9AE77003307A9 /* DetailCellKV.m in Sources */,
 				42604127201C578B002374A8 /* ShipSearchController.m in Sources */,
 				713AA7A41917373600B44092 /* LocalDocumentsViewController.m in Sources */,

+ 19 - 0
Apex Mobile/Apex Mobile/Main.storyboard

@@ -84,11 +84,30 @@
                     <view key="view" contentMode="scaleToFill" id="QxY-X5-VD0">
                         <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                        <subviews>
+                            <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" rowHeight="110" estimatedRowHeight="110" sectionHeaderHeight="-1" sectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="Vjd-jz-qR0">
+                                <rect key="frame" x="0.0" y="20" width="375" height="598"/>
+                                <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
+                                <connections>
+                                    <outlet property="dataSource" destination="XAM-wb-CvU" id="UGh-l6-38n"/>
+                                    <outlet property="delegate" destination="XAM-wb-CvU" id="PnA-NI-Z60"/>
+                                </connections>
+                            </tableView>
+                        </subviews>
                         <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+                        <constraints>
+                            <constraint firstItem="Ipg-Ej-dwR" firstAttribute="trailing" secondItem="Vjd-jz-qR0" secondAttribute="trailing" id="Hxm-ei-DV8"/>
+                            <constraint firstItem="Vjd-jz-qR0" firstAttribute="top" secondItem="Ipg-Ej-dwR" secondAttribute="top" id="K9u-F5-9rH"/>
+                            <constraint firstItem="Vjd-jz-qR0" firstAttribute="leading" secondItem="Ipg-Ej-dwR" secondAttribute="leading" id="WDl-k5-IvU"/>
+                            <constraint firstItem="Ipg-Ej-dwR" firstAttribute="bottom" secondItem="Vjd-jz-qR0" secondAttribute="bottom" id="iTX-qv-NhV"/>
+                        </constraints>
                         <viewLayoutGuide key="safeArea" id="Ipg-Ej-dwR"/>
                     </view>
                     <tabBarItem key="tabBarItem" title="History" image="tab_history" id="TGe-qX-0UY"/>
                     <simulatedTabBarMetrics key="simulatedBottomBarMetrics"/>
+                    <connections>
+                        <outlet property="shipTableView" destination="Vjd-jz-qR0" id="fxU-pP-YLW"/>
+                    </connections>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="p9x-xF-EfO" userLabel="First Responder" sceneMemberID="firstResponder"/>
             </objects>

+ 207 - 8
Apex Mobile/Apex Mobile/OrderHistoryViewController.m

@@ -7,8 +7,19 @@
 //
 
 #import "OrderHistoryViewController.h"
+#import "ShipingStatusCell.h"
+#import "JLRefreshHeader.h"
+#import "JLRefreshFooter.h"
 
-@interface OrderHistoryViewController ()
+#define HISTORY_SHIP_CELL_IDENTIFIER @"HistoryShippingStatusCell"
+static const int delta = 7;
+
+@interface OrderHistoryViewController () <UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,JLRefreshDelegate>
+
+@property (strong, nonatomic) IBOutlet UITableView *shipTableView;
+@property (nonatomic,strong) NSMutableArray *shipArray;
+@property (nonatomic,strong) JLRefreshHeader *refreshHeader;
+@property (nonatomic,strong) JLRefreshFooter *refreshFooter;
 
 @end
 
@@ -17,6 +28,9 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view.
+    
+    [self configureTableView];
+    [self loadData];
 }
 
 - (void)didReceiveMemoryWarning {
@@ -24,14 +38,199 @@
     // Dispose of any resources that can be recreated.
 }
 
-/*
-#pragma mark - Navigation
+- (void)configureTableView {
+    
+    CGFloat w = CGRectGetWidth(self.shipTableView.bounds);
+    self.shipTableView.tableHeaderView =  [[UIView alloc] initWithFrame:CGRectMake(0, 0, w, CGFLOAT_MIN)];
+    self.shipTableView.tableFooterView = [UIView new];
+    
+    [self.shipTableView registerNib:[UINib nibWithNibName:@"ShippingStatusCell" bundle:nil] forCellReuseIdentifier:HISTORY_SHIP_CELL_IDENTIFIER];
+    
+    
+    self.refreshHeader = [[JLRefreshHeader alloc] init];
+    self.refreshHeader.refreshDelegate = self;
+    self.shipTableView.jl_header = self.refreshHeader;
+    
+    self.refreshFooter = [[JLRefreshFooter alloc] init];
+    self.refreshFooter.refreshDelegate = self;
+    self.shipTableView.jl_footer = self.refreshFooter;
+}
+
+#pragma mark - Load Data
+
+- (NSMutableArray *)shipArray {
+    if (!_shipArray) {
+        _shipArray = [NSMutableArray array];
+    }
+    return _shipArray;
+}
+
+- (void)loadData {
+    
+    __weak typeof(self) weakSelf = self;
+    [self loadContentWithOption:0 Complete:^(int result, int count) {
+        [weakSelf.shipTableView reloadData];
+    }];
+}
+
+/**
+ * 0: init load
+ * 1: refresh
+ * 2: load more
+ */
+- (void)loadContentWithOption:(int)option Complete:(void (^)(int result,int count))finish {
+    
+    NSInteger offset = 0;
+    if (option == 2) {
+        offset = self.shipArray.count;
+    }
+    
+    __weak typeof(self) weakSelf = self;
+    dispatch_async(dispatch_get_global_queue(0, 0), ^{
+       
+        NSString *path = [[NSBundle mainBundle] pathForResource:@"fake_container_list.json" ofType:nil];
+        NSData *data = [[NSData alloc] initWithContentsOfFile:path];
+        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
+        
+        dispatch_async(dispatch_get_main_queue(), ^{
+            
+            int result = [[json objectForKey:@"result"] intValue];
+            
+            result = 2;
+            int count = 0;
+            
+            if (result == 2) {
+                NSArray *contentArray = [json objectForKey:@"container_list"];
+                count = (int)contentArray.count;
+                
+                switch (option) {
+                    case 0: {
+                        [weakSelf.shipArray removeAllObjects];
+                        [weakSelf.shipArray addObjectsFromArray:contentArray];
+                    }
+                        break;
+                    case 1: {
+                        [contentArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+                           
+                            [weakSelf.shipArray insertObject:obj atIndex:0];
+                            
+                        }];
+                    }
+                        break;
+                    case 2: {
+                        [weakSelf.shipArray addObjectsFromArray:contentArray];
+                    }
+                        break;
+                    default:
+                        break;
+                }
+                
+            }
+            
+            if (finish) {
+                finish(result,count);
+            }
+            
+        });
+        
+    });
+    
+   
+    
+    
+}
+
+#pragma mark - Actino
+
+
+
+#pragma mark - TableView DataSource && Delegate
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+    return self.shipArray.count;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+    return 1;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+    
+    ShipingStatusCell *cell = [tableView dequeueReusableCellWithIdentifier:HISTORY_SHIP_CELL_IDENTIFIER forIndexPath:indexPath];
+    
+    NSDictionary *item = [self.shipArray objectAtIndex:indexPath.section];
+    
+    NSString *status = [item objectForKey:@"315_status"];
+    NSString *icon = [item objectForKey:@"icon"];
+    NSString *desc = [item objectForKey:@"description"];
+    NSString *detail = [item objectForKey:@"detail"];
+    NSString *time = [item objectForKey:@"date_time"];
+    NSString *location = [item objectForKey:@"last_location"];
+    
+    [[[[[[cell setStatus:status] setDescription:desc] setDetail:detail] setLastLocation:location] setTime:time] setIcon:icon];
+    
+    return cell;
+}
+
+- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
+    return 0.1;
+}
+
+- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
+    return 10;
+}
+
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
+    return 110;
+}
+
+#pragma mark - RefreshDelegate
+
+- (void)jl_beginRefresh:(JLRefreshBasis *)refresh {
+    
+    int option = 0;
+    if ([refresh isEqual:self.refreshHeader]) {
+        option = 1;
+        
+    }
+    if (refresh == self.refreshFooter) {
+        if(refresh.state==JLRefreshStateNoMore) //数据取完不再加载
+            return;
+        option = 2;
+    }
+    __weak typeof(self) weakSelf = self;
+    [self loadContentWithOption:option Complete:^(int result, int count) {
+        if (refresh == weakSelf.refreshHeader) {
+            [weakSelf.refreshHeader performSelector:@selector(endRefresh)];
+        }
+        
+        if (refresh == weakSelf.refreshFooter) {
+            [weakSelf.refreshFooter performSelector:@selector(endRefresh)];
+            if (result == 2 && count < delta) {
+                [weakSelf.refreshFooter performSelector:@selector(noMoreData)];
+            }
+        }
+    }];
+}
+
+- (void)jl_pullRefresh:(JLRefreshBasis *)refresh state:(JLRefreshState)state percentage:(float)percentage {
+    
+    if (refresh == self.shipTableView.jl_header) {
+        
+    }
+    
+    if (refresh == self.shipTableView.jl_footer) {
+        
+    }
+}
 
-// In a storyboard-based application, you will often want to do a little preparation before navigation
-- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
-    // Get the new view controller using [segue destinationViewController].
-    // Pass the selected object to the new view controller.
+- (void)jl_endRefresh:(JLRefreshBasis *)refresh {
+    
+    // refresh UI
+    [self.shipTableView reloadData];
+    if (refresh == self.shipTableView.jl_footer && refresh.state == JLRefreshStateNoMore) {
+        
+    }
 }
-*/
 
 @end