project list view almost done

This commit is contained in:
zhijie lee 2013-07-15 02:59:19 +08:00
parent 800354adee
commit 863bfa7564
9 changed files with 208 additions and 23 deletions

View File

@ -38,6 +38,7 @@
D5DB80B61793016B0081662A /* OZLAccountViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D5DB80B41793016B0081662A /* OZLAccountViewController.xib */; };
D5DB80BA17930C830081662A /* OZLNetworkBase.m in Sources */ = {isa = PBXBuildFile; fileRef = D5DB80B917930C830081662A /* OZLNetworkBase.m */; };
D5DB80BD17930ECD0081662A /* OZLSingleton.m in Sources */ = {isa = PBXBuildFile; fileRef = D5DB80BC17930ECD0081662A /* OZLSingleton.m */; };
D5DB80C217931C8B0081662A /* OZLModelProject.m in Sources */ = {isa = PBXBuildFile; fileRef = D5DB80C117931C8B0081662A /* OZLModelProject.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -96,6 +97,8 @@
D5DB80B917930C830081662A /* OZLNetworkBase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OZLNetworkBase.m; path = Utils/OZLNetworkBase.m; sourceTree = "<group>"; };
D5DB80BB17930ECD0081662A /* OZLSingleton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OZLSingleton.h; path = Utils/OZLSingleton.h; sourceTree = "<group>"; };
D5DB80BC17930ECD0081662A /* OZLSingleton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OZLSingleton.m; path = Utils/OZLSingleton.m; sourceTree = "<group>"; };
D5DB80C017931C8B0081662A /* OZLModelProject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OZLModelProject.h; path = Models/OZLModelProject.h; sourceTree = "<group>"; };
D5DB80C117931C8B0081662A /* OZLModelProject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OZLModelProject.m; path = Models/OZLModelProject.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -143,6 +146,7 @@
D5DB805F1792F2BF0081662A /* RedmineMobile */ = {
isa = PBXGroup;
children = (
D5DB80BF17931C580081662A /* Models */,
D5DB80AE1793008F0081662A /* Utils */,
D5DB80A81792F4E40081662A /* ViewControllers */,
D5DB80681792F2BF0081662A /* OZLAppDelegate.h */,
@ -261,6 +265,15 @@
name = Utils;
sourceTree = "<group>";
};
D5DB80BF17931C580081662A /* Models */ = {
isa = PBXGroup;
children = (
D5DB80C017931C8B0081662A /* OZLModelProject.h */,
D5DB80C117931C8B0081662A /* OZLModelProject.m */,
);
name = Models;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -351,6 +364,7 @@
D5DB80B51793016B0081662A /* OZLAccountViewController.m in Sources */,
D5DB80BA17930C830081662A /* OZLNetworkBase.m in Sources */,
D5DB80BD17930ECD0081662A /* OZLSingleton.m in Sources */,
D5DB80C217931C8B0081662A /* OZLModelProject.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -0,0 +1,21 @@
//
// OZLModelProject.h
// RedmineMobile
//
// Created by Lee Zhijie on 7/15/13.
// Copyright (c) 2013 Lee Zhijie. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface OZLModelProject : NSObject
@property(nonatomic) int index;
@property(nonatomic,strong) NSString* description;
@property(nonatomic,strong) NSString* name;
@property(nonatomic) int parentId;
@property(nonatomic,strong) NSString* createdOn;
@property(nonatomic,strong) NSString* updatedOn;
-(id)initWithDictionary:(NSDictionary*)dic;
@end

View File

@ -0,0 +1,34 @@
//
// OZLModelProject.m
// RedmineMobile
//
// Created by Lee Zhijie on 7/15/13.
// Copyright (c) 2013 Lee Zhijie. All rights reserved.
//
#import "OZLModelProject.h"
@implementation OZLModelProject
-(id)initWithDictionary:(NSDictionary*)dic
{
self = [super init];
if (!self) {
return nil;
}
_index = [[dic objectForKey:@"id"] intValue];
_name = [dic objectForKey:@"name"];
_description = [dic objectForKey:@"description"];
_createdOn = [dic objectForKey:@"created_on"];
_updatedOn = [dic objectForKey:@"updated_on"];
NSDictionary* parent = [dic objectForKey:@"parent"];
if (parent) {
_parentId = [[parent objectForKey:@"id"] intValue];
}else {
_parentId = -1;
}
return self;
}
@end

View File

@ -10,6 +10,6 @@
@interface OZLNetwork : NSObject
+(void)getProjectListWithBlock:(void (^)(NSDictionary *result, NSError *error))block;
+(void)getProjectListWithParams:(NSDictionary*)params andBlock:(void (^)(NSArray *result, NSError *error))block;
@end

View File

@ -9,18 +9,25 @@
#import "OZLNetwork.h"
#import "OZLNetworkBase.h"
#import "AFHTTPRequestOperation.h"
#import "JSONKit.h"
#import "OZLModelProject.h"
@implementation OZLNetwork
+(void)getProjectListWithBlock:(void (^)(NSDictionary *result, NSError *error))block
+(void)getProjectListWithParams:(NSDictionary*)params andBlock:(void (^)(NSArray *result, NSError *error))block;
{
NSString* path = @"/projects.json";
NSDictionary* params = [[NSDictionary alloc] initWithObjectsAndKeys: nil];
[[OZLNetworkBase sharedClient] getPath:path parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (block) {
NSLog(@"the repsonse:%@",responseObject);
block(responseObject,nil);
NSMutableArray* projects = [[NSMutableArray alloc] init];
NSArray* projectsDic = [responseObject objectForKey:@"projects"];
for (NSDictionary* p in projectsDic) {
[projects addObject:[[OZLModelProject alloc] initWithDictionary:p]];
}
block(projects,nil);
}
@ -28,7 +35,7 @@
if (block) {
block(nil, error);
block([NSArray array], error);
}
}];

View File

@ -88,8 +88,6 @@
[[OZLSingleton sharedInstance] setRedmineUserKey:_redmineUserKey.text];
[[OZLSingleton sharedInstance] setRedmineHomeURL:_redmineHomeURL.text];
[OZLNetwork getProjectListWithBlock:^(NSDictionary *respond, NSError *error) {
NSLog(@"respond:%@",respond.description);
}];
[self showLeft];
}
@end

View File

@ -8,7 +8,8 @@
#import <UIKit/UIKit.h>
@interface OZLProjectListViewController : UIViewController
@interface OZLProjectListViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *projectsTableview;
- (IBAction)showAccountView:(id)sender;
@end

View File

@ -10,8 +10,13 @@
#import "PPRevealSideViewController.h"
#import "OZLProjectViewController.h"
#import "OZLAccountViewController.h"
#import "OZLNetwork.h"
#import "OZLModelProject.h"
@interface OZLProjectListViewController ()
@interface OZLProjectListViewController (){
NSMutableArray* _projectList;
}
@end
@ -29,9 +34,20 @@
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
_projectsTableview.delegate = self;
_projectsTableview.dataSource = self;
}
-(void) viewWillAppear:(BOOL)animated
{
// refresh project list
[OZLNetwork getProjectListWithParams:nil andBlock:^(NSArray *result, NSError *error) {
NSLog(@"respond:%@",result.description);
_projectList = [[NSMutableArray alloc] initWithArray: result];
[_projectsTableview reloadData];
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
@ -53,4 +69,90 @@
[self.revealSideViewController popViewControllerWithNewCenterController:n
animated:YES];
}
- (void)viewDidUnload {
[self setProjectsTableview:nil];
[super viewDidUnload];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [_projectList count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 44;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString* cellidentifier = [NSString stringWithFormat:@"project_cell_id_%d",indexPath.row];
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellidentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellidentifier];
}
OZLModelProject* project = [_projectList objectAtIndex:indexPath.row];
cell.textLabel.text = project.name;
cell.detailTextLabel.text = project.description;
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
@end

View File

@ -36,12 +36,12 @@
<reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="IBUIButton" id="343219807">
<object class="IBUIButton" id="586838365">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrameSize">{320, 44}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSNextKeyView" ref="505299930"/>
<reference key="NSNextKeyView" ref="505504489"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
@ -49,7 +49,7 @@
<int key="IBUIContentVerticalAlignment">0</int>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">Account</string>
<object class="NSColor" key="IBUIHighlightedTitleColor" id="885473536">
<object class="NSColor" key="IBUIHighlightedTitleColor" id="152654569">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
</object>
@ -71,13 +71,13 @@
<int key="NSfFlags">16</int>
</object>
</object>
<object class="IBUITableView" id="505299930">
<object class="IBUITableView" id="505504489">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">274</int>
<string key="NSFrame">{{0, 45}, {320, 503}}</string>
<reference key="NSSuperview" ref="191373211"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<reference key="IBUIBackgroundColor" ref="885473536"/>
<reference key="IBUIBackgroundColor" ref="152654569"/>
<bool key="IBUIClipsSubviews">YES</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIAlwaysBounceVertical">YES</bool>
@ -91,7 +91,7 @@
</array>
<string key="NSFrame">{{0, 20}, {320, 548}}</string>
<reference key="NSSuperview"/>
<reference key="NSNextKeyView" ref="343219807"/>
<reference key="NSNextKeyView" ref="586838365"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
@ -130,10 +130,18 @@
</object>
<int key="connectionID">3</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">projectsTableview</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="505504489"/>
</object>
<int key="connectionID">20</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">showAccountView:</string>
<reference key="source" ref="343219807"/>
<reference key="source" ref="586838365"/>
<reference key="destination" ref="372490531"/>
<int key="IBEventType">7</int>
</object>
@ -152,8 +160,8 @@
<int key="objectID">1</int>
<reference key="object" ref="191373211"/>
<array class="NSMutableArray" key="children">
<reference ref="343219807"/>
<reference ref="505299930"/>
<reference ref="586838365"/>
<reference ref="505504489"/>
</array>
<reference key="parent" ref="0"/>
</object>
@ -170,13 +178,13 @@
</object>
<object class="IBObjectRecord">
<int key="objectID">4</int>
<reference key="object" ref="343219807"/>
<reference key="object" ref="586838365"/>
<array class="NSMutableArray" key="children"/>
<reference key="parent" ref="191373211"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">9</int>
<reference key="object" ref="505299930"/>
<reference key="object" ref="505504489"/>
<array class="NSMutableArray" key="children"/>
<reference key="parent" ref="191373211"/>
</object>
@ -195,7 +203,7 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
<int key="maxID">17</int>
<int key="maxID">20</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes"/>
<int key="IBDocument.localizationMode">0</int>