mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-21 02:50:11 +08:00
list view for posts
This commit is contained in:
@@ -34,7 +34,8 @@
|
||||
@"attachment_file_name", @"attachmentFileName",
|
||||
@"attachment_file_size", @"attachmentFileSize",
|
||||
@"attachment_path", @"attachmentPath",
|
||||
@"attachment_updated_at", @"attachment_updated_at",
|
||||
@"attachment_updated_at", @"attachmentUpdatedAt",
|
||||
@"body", @"body",
|
||||
nil];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// DBPostsTableViewController.h
|
||||
// DiscussionBoard
|
||||
//
|
||||
// Created by Jeremy Ellison on 1/7/11.
|
||||
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Three20/Three20.h>
|
||||
|
||||
@interface DBPostsTableViewController : TTTableViewController {
|
||||
NSString* _topicID;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// DBPostsTableViewController.m
|
||||
// DiscussionBoard
|
||||
//
|
||||
// Created by Jeremy Ellison on 1/7/11.
|
||||
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "DBPostsTableViewController.h"
|
||||
#import "DBPost.h"
|
||||
#import <RestKit/Three20/Three20.h>
|
||||
|
||||
@implementation DBPostsTableViewController
|
||||
|
||||
- (id)initWithTopicID:(NSString*)topicID {
|
||||
if (self = [super initWithStyle:UITableViewStylePlain]) {
|
||||
_topicID = [topicID retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_topicID release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)loadView {
|
||||
[super loadView];
|
||||
self.title = @"Posts";
|
||||
self.variableHeightRows = YES;
|
||||
|
||||
NSString* path = [NSString stringWithFormat:@"/topics/%@/posts", _topicID];
|
||||
self.model = [[[RKRequestTTModel alloc] initWithResourcePath:path] autorelease];
|
||||
}
|
||||
|
||||
- (void)didLoadModel:(BOOL)firstTime {
|
||||
RKRequestTTModel* model = (RKRequestTTModel*)self.model;
|
||||
NSMutableArray* items = [NSMutableArray arrayWithCapacity:[model.objects count]];
|
||||
|
||||
for(DBPost* post in model.objects) {
|
||||
NSString* url = @"";
|
||||
[items addObject:[TTTableLongTextItem itemWithText:post.body URL:url]];
|
||||
}
|
||||
|
||||
NSLog(@"Items: %@", items);
|
||||
self.dataSource = [TTListDataSource dataSourceWithItems:items];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
- (void)loadView {
|
||||
[super loadView];
|
||||
self.title = @"Topics";
|
||||
|
||||
self.model = [[[RKRequestTTModel alloc] initWithResourcePath:@"/topics"] autorelease];
|
||||
}
|
||||
@@ -23,7 +24,7 @@
|
||||
NSMutableArray* items = [NSMutableArray arrayWithCapacity:[model.objects count]];
|
||||
|
||||
for(DBTopic* topic in model.objects) {
|
||||
NSString* url = [NSString stringWithFormat:@"db://topic/%@", topic.topicID];
|
||||
NSString* url = [NSString stringWithFormat:@"db://topics/%@/posts", topic.topicID];
|
||||
[items addObject:[TTTableTextItem itemWithText:topic.name URL:url]];
|
||||
}
|
||||
NSLog(@"Items: %@", items);
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#import <Three20/Three20+Additions.h>
|
||||
#import "DBTopicsTableViewController.h"
|
||||
#import "DBTopic.h"
|
||||
#import "DBPostsTableViewController.h"
|
||||
#import "DBPost.h"
|
||||
|
||||
@implementation DiscussionBoardAppDelegate
|
||||
|
||||
@@ -31,11 +33,13 @@
|
||||
RKObjectMapper* mapper = objectManager.mapper;
|
||||
|
||||
[mapper registerClass:[DBTopic class] forElementNamed:@"topic"];
|
||||
[mapper registerClass:[DBPost class] forElementNamed:@"post"];
|
||||
|
||||
// Initialize Three20
|
||||
TTURLMap* map = [[TTNavigator navigator] URLMap];
|
||||
[map from:@"db://topics" toViewController:[DBTopicsTableViewController class]];
|
||||
|
||||
[map from:@"db://topics/(initWithTopicID:)/posts" toViewController:[DBPostsTableViewController class]];
|
||||
[map from:@"*" toViewController:[TTWebController class]];
|
||||
|
||||
TTOpenURL(@"db://topics");
|
||||
[[TTNavigator navigator].window makeKeyAndVisible];
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
3F4563C212D7EA3500BE25AD /* DBPost.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F4563C112D7EA3500BE25AD /* DBPost.m */; };
|
||||
3F76BBD612D7DA9D001562DC /* DataModel.xcdatamodel in Sources */ = {isa = PBXBuildFile; fileRef = 3F76BBD512D7DA9D001562DC /* DataModel.xcdatamodel */; };
|
||||
3F76BBF812D7DB5A001562DC /* DBTopicsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F76BBF712D7DB5A001562DC /* DBTopicsTableViewController.m */; };
|
||||
3FB1FC3712D7ECDF00B2636A /* DBPostsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3FB1FC3612D7ECDF00B2636A /* DBPostsTableViewController.m */; };
|
||||
A7A2D33A12D780DD00683D6F /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7A2D33912D780DD00683D6F /* QuartzCore.framework */; };
|
||||
A7A2D3C412D7829E00683D6F /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7A2D3C312D7829E00683D6F /* CFNetwork.framework */; };
|
||||
A7A2D3C612D7829E00683D6F /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7A2D3C512D7829E00683D6F /* CoreData.framework */; };
|
||||
@@ -473,6 +474,8 @@
|
||||
3F76BBD512D7DA9D001562DC /* DataModel.xcdatamodel */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = wrapper.xcdatamodel; path = DataModel.xcdatamodel; sourceTree = "<group>"; };
|
||||
3F76BBF612D7DB5A001562DC /* DBTopicsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBTopicsTableViewController.h; sourceTree = "<group>"; };
|
||||
3F76BBF712D7DB5A001562DC /* DBTopicsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DBTopicsTableViewController.m; sourceTree = "<group>"; };
|
||||
3FB1FC3512D7ECDF00B2636A /* DBPostsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DBPostsTableViewController.h; sourceTree = "<group>"; };
|
||||
3FB1FC3612D7ECDF00B2636A /* DBPostsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DBPostsTableViewController.m; sourceTree = "<group>"; };
|
||||
8D1107310486CEB800E47090 /* DiscussionBoard-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "DiscussionBoard-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
|
||||
A7A2D33912D780DD00683D6F /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
|
||||
A7A2D39412D7822C00683D6F /* RestKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RestKit.xcodeproj; path = ../../../RestKit.xcodeproj; sourceTree = SOURCE_ROOT; };
|
||||
@@ -530,6 +533,8 @@
|
||||
3F76BBF712D7DB5A001562DC /* DBTopicsTableViewController.m */,
|
||||
3F4563C012D7EA3500BE25AD /* DBPost.h */,
|
||||
3F4563C112D7EA3500BE25AD /* DBPost.m */,
|
||||
3FB1FC3512D7ECDF00B2636A /* DBPostsTableViewController.h */,
|
||||
3FB1FC3612D7ECDF00B2636A /* DBPostsTableViewController.m */,
|
||||
);
|
||||
path = Classes;
|
||||
sourceTree = "<group>";
|
||||
@@ -1171,6 +1176,7 @@
|
||||
3F76BBD612D7DA9D001562DC /* DataModel.xcdatamodel in Sources */,
|
||||
3F76BBF812D7DB5A001562DC /* DBTopicsTableViewController.m in Sources */,
|
||||
3F4563C212D7EA3500BE25AD /* DBPost.m in Sources */,
|
||||
3FB1FC3712D7ECDF00B2636A /* DBPostsTableViewController.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1234,6 +1240,7 @@
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
GCC_PREFIX_HEADER = DiscussionBoard_Prefix.pch;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
|
||||
HEADER_SEARCH_PATHS = (
|
||||
../../../Build,
|
||||
Libraries/three20/Build/Products/three20,
|
||||
@@ -1255,6 +1262,7 @@
|
||||
COPY_PHASE_STRIP = YES;
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
GCC_PREFIX_HEADER = DiscussionBoard_Prefix.pch;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
|
||||
HEADER_SEARCH_PATHS = (
|
||||
../../../Build,
|
||||
Libraries/three20/Build/Products/three20,
|
||||
|
||||
Reference in New Issue
Block a user