Browse files

Basic table view function

  • Loading branch information...
1 parent 58e32e1 commit 01d6ae01b58cb8386da55eaabf6284b8190291d0 @winfield committed Mar 4, 2012
View
12 Ruby China.xcodeproj/project.pbxproj
@@ -24,6 +24,8 @@
F3D5460B1503A5BC00F5A9E3 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F3D5460A1503A5BC00F5A9E3 /* QuartzCore.framework */; };
F3D5460D1503A5CE00F5A9E3 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F3D5460C1503A5CE00F5A9E3 /* libxml2.dylib */; };
F3D5462B1503A76700F5A9E3 /* libRestKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F3D546241503A62F00F5A9E3 /* libRestKit.a */; };
+ F3D546411503B7BA00F5A9E3 /* RCITopic.m in Sources */ = {isa = PBXBuildFile; fileRef = F3D546401503B7BA00F5A9E3 /* RCITopic.m */; };
+ F3D546511503B89F00F5A9E3 /* RCIUser.m in Sources */ = {isa = PBXBuildFile; fileRef = F3D546501503B89E00F5A9E3 /* RCIUser.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -87,6 +89,10 @@
F3D546071503A5B000F5A9E3 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
F3D5460A1503A5BC00F5A9E3 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
F3D5460C1503A5CE00F5A9E3 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; };
+ F3D5463F1503B7BA00F5A9E3 /* RCITopic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCITopic.h; sourceTree = "<group>"; };
+ F3D546401503B7BA00F5A9E3 /* RCITopic.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCITopic.m; sourceTree = "<group>"; };
+ F3D5464F1503B89E00F5A9E3 /* RCIUser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCIUser.h; sourceTree = "<group>"; };
+ F3D546501503B89E00F5A9E3 /* RCIUser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCIUser.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -155,6 +161,10 @@
F3269DA3150390E100C7D2DA /* MainStoryboard_iPad.storyboard */,
F3269DA6150390E100C7D2DA /* RCIViewController.h */,
F3269DA7150390E100C7D2DA /* RCIViewController.m */,
+ F3D5463F1503B7BA00F5A9E3 /* RCITopic.h */,
+ F3D546401503B7BA00F5A9E3 /* RCITopic.m */,
+ F3D5464F1503B89E00F5A9E3 /* RCIUser.h */,
+ F3D546501503B89E00F5A9E3 /* RCIUser.m */,
F3269D95150390E000C7D2DA /* Supporting Files */,
);
path = "Ruby China";
@@ -288,6 +298,8 @@
F3269D9B150390E000C7D2DA /* main.m in Sources */,
F3269D9F150390E100C7D2DA /* RCIAppDelegate.m in Sources */,
F3269DA8150390E100C7D2DA /* RCIViewController.m in Sources */,
+ F3D546411503B7BA00F5A9E3 /* RCITopic.m in Sources */,
+ F3D546511503B89F00F5A9E3 /* RCIUser.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
BIN ...deproj/project.xcworkspace/xcuserdata/winfield.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
View
5 Ruby China.xcodeproj/xcuserdata/winfield.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Bucket
+ type = "1"
+ version = "1.0">
+</Bucket>
View
55 Ruby China/RCIAppDelegate.m
@@ -8,42 +8,45 @@
#import "RCIAppDelegate.h"
#import <RestKit/RestKit.h>
+#import "RCIUser.h"
+#import "RCITopic.h"
+
+/*#ifdef DEBUG
+ static NSString * API_ENDPOINT = @"http://localhost:3000";
+ #else*/
+static NSString * API_ENDPOINT = @"http://ruby-china.org";
+//#endif
@implementation RCIAppDelegate
@synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
- // Override point for customization after application launch.
+ [self initRestKit];
return YES;
}
-- (void)applicationWillResignActive:(UIApplication *)application
-{
- // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
- // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
-}
-
-- (void)applicationDidEnterBackground:(UIApplication *)application
-{
- // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
-}
-
-- (void)applicationWillEnterForeground:(UIApplication *)application
-{
- // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
-}
-
-- (void)applicationDidBecomeActive:(UIApplication *)application
-{
- // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
-}
-
-- (void)applicationWillTerminate:(UIApplication *)application
-{
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+- (void)initRestKit {
+ RKObjectManager *manager = [RKObjectManager objectManagerWithBaseURL:API_ENDPOINT];
+//
+// RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[RCIUser class]];
+// [userMapping mapAttributes:@"login", @"name", @"location", @"bio", @"tagline", @"website", nil];
+// [userMapping mapKeyPathsToAttributes:@"github_url", @"githubUrl",
+// @"gravatar_hash", @"gravatarHash",
+// nil];
+// [manager.mappingProvider addObjectMapping:userMapping];
+
+ RKObjectMapping *topicMapping = [RKObjectMapping mappingForClass:[RCITopic class]];
+ [topicMapping mapKeyPathsToAttributes: @"title", @"title",
+ @"replies_count", @"repliesCount",
+ @"created_at", @"createdDate",
+ @"updated_at", @"updatedDate",
+ @"node_name", @"nodeName",
+ nil];
+// [topicMapping mapRelationship:@"user" withMapping:userMapping];
+
+ [manager.mappingProvider addObjectMapping:topicMapping];
}
@end
View
21 Ruby China/RCITopic.h
@@ -0,0 +1,21 @@
+//
+// RCITopic.h
+// Ruby China
+//
+// Created by 来 诺 on 3/4/12.
+// Copyright (c) 2012 lainuo.info. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "RCIUser.h"
+
+@interface RCITopic : NSObject
+
+@property (nonatomic, strong) NSString *title;
+@property (nonatomic, strong) NSNumber *repliesCount;
+@property (nonatomic, strong) NSDate *createdDate;
+@property (nonatomic, strong) NSDate *updatedDate;
+@property (nonatomic, strong) NSString *nodeName;
+//@property (nonatomic, strong) RCIUser *user;
+
+@end
View
19 Ruby China/RCITopic.m
@@ -0,0 +1,19 @@
+//
+// RCITopic.m
+// Ruby China
+//
+// Created by 来 诺 on 3/4/12.
+// Copyright (c) 2012 lainuo.info. All rights reserved.
+//
+
+#import "RCITopic.h"
+
+@implementation RCITopic
+@synthesize title = _title;
+@synthesize repliesCount = _repliesCount;
+@synthesize createdDate = _createdDate;
+@synthesize updatedDate = _updatedDate;
+@synthesize nodeName = _nodeName;
+//@synthesize user = _user;
+
+@end
View
13 Ruby China/RCIUser.h
@@ -0,0 +1,13 @@
+//
+// RCIUser.h
+// Ruby China
+//
+// Created by 来 诺 on 3/4/12.
+// Copyright (c) 2012 lainuo.info. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface RCIUser : NSObject
+
+@end
View
13 Ruby China/RCIUser.m
@@ -0,0 +1,13 @@
+//
+// RCIUser.m
+// Ruby China
+//
+// Created by 来 诺 on 3/4/12.
+// Copyright (c) 2012 lainuo.info. All rights reserved.
+//
+
+#import "RCIUser.h"
+
+@implementation RCIUser
+
+@end
View
3 Ruby China/RCIViewController.h
@@ -7,7 +7,8 @@
//
#import <UIKit/UIKit.h>
+#import <RestKit/RestKit.h>
-@interface RCIViewController : UITableViewController
+@interface RCIViewController : UITableViewController <RKObjectLoaderDelegate>
@end
View
56 Ruby China/RCIViewController.m
@@ -7,17 +7,24 @@
//
#import "RCIViewController.h"
+#import "RCITopic.h"
@interface RCIViewController ()
-
+@property (nonatomic, strong) NSArray *topics;
+@property (nonatomic, weak) IBOutlet UITableView* topicTableView;
@end
@implementation RCIViewController
+@synthesize topicTableView = _topicTableView;
+@synthesize topics = _topics;
- (void)viewDidLoad
{
[super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
+
+ RKObjectMapping *topicMappping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[RCITopic class]];
+ [[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/api/topics.json" objectMapping:topicMappping delegate:self];
+
}
- (void)viewDidUnload
@@ -35,4 +42,49 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}
}
+#pragma mark - RKObjectLoaderDelegate
+
+- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
+ self.topics = [objects copy];
+ [self.topicTableView reloadData];
+}
+
+- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error {
+}
+
+#pragma mark - UITableViewDataSource
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ return [self.topics count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ static NSString *CellIdentifier = @"Topic Summary";
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+
+ RCITopic *topic = [self.topics objectAtIndex:indexPath.row];
+ cell.textLabel.text = topic.title;
+
+ return cell;
+}
+
+#pragma mark - UITableViewDelegate
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ // Navigation logic may go here. Create and push another view controller.
+ /*
+ <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
+ // ...
+ // Pass the selected object to the new view controller.
+ [self.navigationController pushViewController:detailViewController animated:YES];
+ */
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+}
+
@end
View
41 Ruby China/en.lproj/MainStoryboard_iPhone.storyboard
@@ -14,12 +14,51 @@
<rect key="frame" x="0.0" y="20" width="320" height="460"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+ <prototypes>
+ <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Topic Summary" textLabel="9dc-tN-qlf" detailTextLabel="wE2-KC-EMu" style="IBUITableViewCellStyleValue1" id="qRX-Z2-oP2">
+ <rect key="frame" x="0.0" y="22" width="320" height="44"/>
+ <autoresizingMask key="autoresizingMask"/>
+ <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
+ <rect key="frame" x="0.0" y="0.0" width="320" height="43"/>
+ <autoresizingMask key="autoresizingMask"/>
+ <subviews>
+ <label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" id="9dc-tN-qlf">
+ <rect key="frame" x="10" y="11" width="35" height="21"/>
+ <autoresizingMask key="autoresizingMask"/>
+ <fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+ </label>
+ <label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" id="wE2-KC-EMu">
+ <rect key="frame" x="266" y="11" width="44" height="21"/>
+ <autoresizingMask key="autoresizingMask"/>
+ <fontDescription key="fontDescription" type="system" pointSize="17"/>
+ <color key="textColor" red="0.2196078431372549" green="0.32941176470588235" blue="0.52941176470588236" alpha="1" colorSpace="calibratedRGB"/>
+ <color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
+ </label>
+ </subviews>
+ <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
+ </view>
+ </tableViewCell>
+ </prototypes>
+ <sections/>
</tableView>
+ <connections>
+ <outlet property="topicTableView" destination="p9L-iJ-y4w" id="BkX-Ny-9ak"/>
+ </connections>
</viewController>
</objects>
- <point key="canvasLocation" x="173" y="16"/>
+ <point key="canvasLocation" x="155" y="-40"/>
</scene>
</scenes>
+ <classes>
+ <class className="RCIViewController" superclassName="UITableViewController">
+ <source key="sourceIdentifier" type="project" relativePath="./Classes/RCIViewController.h"/>
+ <relationships>
+ <relationship kind="outlet" name="topicTableView" candidateClass="UITableView"/>
+ </relationships>
+ </class>
+ </classes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>

0 comments on commit 01d6ae0

Please sign in to comment.