LoginSignup
28
28

More than 5 years have passed since last update.

RailsとiPhoneではじめるアプリケーション開発をiOS7向けに読み進めるときの注意・修正点

Last updated at Posted at 2013-11-03

RailsとiPhoneではじめるアプリケーション開発の初版第一刷187ページから写経を始めた。

しかし、この本、誤植・タイポが非常に多い。なので、修正しながら読み進めていく。

みんなで正誤表 http://public-errata.appspot.com/errata/book/9784844334477/ にも誤記・誤植の情報がある。

8

206ページ

〜〜Controllerの6つのクラスを作る。「まず、〜〜作成します」と記述されているがこれから作成するのか、このページでもう作成してしまうのか不明瞭。ここで作るのが正解。

グループ名はLefMenu。LeftMenuのタイポ? もしかしたら後々になって重要な意味を持ってくるかもしれないのでとりあえずLefMenuのまま続行する。

208ページ

8.5.2にて。一気にに省略してしまうかと思ってひやひやした。実際は8.5.3にて実装する。

209ページ

#pragma mark - Datam setter

とは? DataかDatumのタイポと思われる。どっちのタイポかわからん。とりあえずDataにしておいた。

210ページ

tableView:tableView:cellForRowAtIndexPath:indexPath

TPLeftMenuController.m
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

と書いてあるがよく見てみるとおかしい。まず@"Cell"が片方は大文字、もう片方は小文字になってる。どっちを使うのか一貫してほしいし、現時点ではどちらが正しいのか不明。そしてせっかく定義したCellIdentifierをなぜ使わないのか理解できない。

また、なぜCellIdentifierと大文字で始まる変数名にしたのかわからない。staticなIdentifierは大文字にする、といった慣習があるのだろうか?

TPLeftMenuController.m
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.text = self.menuList[indexPath.row][0];
    return cell;
}

こう書き直した。あとで問題が出たらまた書き直す。Cellの大文字小文字あたりで問題でる可能性あり。

viewDidLoad

本によれば、210ページまで実装できればメニューにtableViewが表示されるとう。しかし実装しても、まだtableViewは出ない。なぜならviewにtableViewをaddSubViewしていないから。

TPLeftMenuController.m
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:self.tableView];  // 追加
}

と、viewDidLoadに [self.view addSubview:self.tableView];を追加する。

211ページ

TPConstants.hをTravelPhoto-Prefix.pchでインポートする、とあるがそのコードが書かれていない。この短い文章で察しろとは怠惰にして傲慢。なお、この本通りに作っていればTravelPhoto-Previx.pchではなくtravelphoto-Prefix.pchとなっているはず。ここに限ったことではないが大文字と小文字の扱いが粗雑すぎる。

travelphoto-Prefix.pch
//
//  Prefix header
//
//  The contents of this file are implicitly included at the beginning of every source file.
//

#import <Availability.h>

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <CoreData/CoreData.h>

    #define MR_SHORTHAND
    #import "CoreData+MagicalRecord.h"
#import "TPConstants.h"
#import "TPUserInfo.h"
#endif

212ページ

AppDelegate.mではなくTPAppDelegate.mとなる。なおこのコードはdidFinishLaunchingWithOptionsのどこに書いてもよい。後でも先でも大丈夫。211ページでtravelphoto-Prefix.pchを編集していないとwarningが出る。

10

228ページ

travelphoto-Prefix.pchにてライブラリのインポートを行う。

#import "QRootElement.h"
#import "QuickDialogController.h"

をtravelphoto-Prefix.pchに追加。

TPAppDelegate.m
[self.viewController presentedViewController:self.tpLoginNav animated:YES completion:nil];

の部分でNo visible @interface for 'JASidePanelController'エラーが出る。修正方法がわからない。とりあえず飛ばす。JASidePanelControllerではpresentedViewControllerでモーダルで別のVCを呼んでくることができないのだろうか?

229ページ

TPConstants.c
#import <Foundation/Foundation.h>

@interface TPConstants : NSObject
extern NSString *const TPShowPanel;
extern NSString *const TPShowLogin; // 追加

@end

TPConstants.m
#import "TPConstants.h"

@implementation TPConstants

NSString *const TPShowPanel = @"TPShowPanel";
NSString *const TPShowLogin = @"TPShowLogin";  // 追加

@end

以上のようにTPConstants.mを修正。

230ページ

self.rootの不在

TPLoginController.mのviewDidLoadでself.rootがないと怒られる。

TPLoginController.h
#import <UIKit/UIKit.h>

@interface TPLoginController : UIViewController
@property (strong, nonatomic) UINavigationController *root;

@end

と修正した。

QEntryElementのimport

TPLoginController.m
QEntryElement *email = [[QEntryElement alloc] initWithKey:@"email"];

の部分で

Receiver 'QEntryElement' for class message if a forward declaration

と怒られた。

TPAppDeletate.m

#import "TPAppDelegate.h"
#import "JASidePanelController.h"
#import "TPLeftMenuController.h"
#import "TPMypageController.h"
#import "QRootElement.h"  //追加
#import "QEntryElement.h" //追加

@implementation TPAppDelegate

@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
@synthesize viewController = _viewController;

と、TPAppDelegateにimport文を追加。

travelphoto-Prefix.pch
#import <Availability.h>

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <CoreData/CoreData.h>

    #define MR_SHORTHAND
    #import "CoreData+MagicalRecord.h"
    #import "TPConstants.h"
    #import "TPUserInfo.h"
    #import "QRootElement.h"  //追加
    #import "QEntryElement.h" //追加
    #import "QuickDialogController.h"
#endif

travelphoto-Prefix.pchにおいても、以上のように修正する。

28
28
8

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
28