0

私は XCode5 を理解しようとしていますが、ほとんどのコード サンプルは XCode5 以前のものです。そしてもちろんiOS7以前。主な問題はストーリーボードです。多くの人が、ストーリーボードなしで SCode5 をビルドする方法を知りたがっていますが、私は、ストーリーボード前のコードをストーリーボード コードに移動する方法を知りたくありません。

例えば。最も優れた本、「Geolocation in iOS」Alasdair Allan 著、O'Reilly、2012 年には、数リリース前に書かれたコードが満載です。もちろん、私は XCode5/iOS7 レベルで XCode に参加しているため、さまざまな部分で何を話しているのかわかりません。サンプル コードの最初の部分は動作しているようですが、現在エラーが発生しており、理解できません。Code4の方法でやろうとしていて、私はXCode5にいるのではないかと思います。

とにかく、何を変更するかを指摘するチュートリアルがあればいいでしょう。例を挙げましょう。この本の最初の例のコードは次のようになります。

本の Project Navigator 画像では、次のように表示されます。

LocationAppDelegate.h
LocationAppDelegate.m
LocationViewController.h
LocationViewController.
LocationViewController.xib

私のディスプレイには、すべて同じファイルがあります。「.xib」ファイルの代わりに「Main.storyboard」があります

これまでのところ、わかりました-私が読んだことから、 Main.storyboard は xib ファイルの新しい同等物であると信じています。しかし、.h ファイルと .m ファイル内で自動的に生成されるコードには多くの違いがあります。最善を尽くした結果、少なくとも位置情報サービスのデバッグ ウィンドウにダミーの位置情報が表示されるようになりました。

しかし、今このエラーがあります。実際には2つのエラーがあります。

最初のセマンティック警告

LocationViewController.m:15:17: Method 'tableView:cellForRowAtIndexPath:' in protocol not implemented

2 つ目は、赤い ! のエラーです。マーク

LocationViewController.m:60:9: No visible @interface for 'UITableView' declares the selector 'dequeueReusableCellWithIndentifier:'

この本に書かれているコードはかなり単純明快ですが、このエラーは私を悩ませました。

LocationViewController.m のコード

//
//  LocationViewController.h
//  Location
//
//  Created by Robert Chalmers on 08/10/2013.
//  Copyright (c) 2013 Robert Chalmers. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface LocationViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) IBOutlet UITableView *tableView;

@end

LocationViewController.m のコード

//
//  LocationViewController.m
//  Location
//
//  Created by Robert Chalmers on 08/10/2013.
//  Copyright (c) 2013 Robert Chalmers. All rights reserved.
//

#import "LocationViewController.h"

@interface LocationViewController ()

@end

@implementation LocationViewController

@synthesize tableView = _tableView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - View lifecycle






#pragma mark UITableViewDelegate Methods

- (void)tableView:(UITableView *)tv
        didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //add code here
}

#pragma mark UITableViewDataSource Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tv {
    return 1;
}

- (NSInteger) tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section {
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *identifier = @"cell";
    UITableViewCell *cell =
    //[tv dequeueReusableCellWithIndentifier:@"cell"];
    [tv dequeueReusableCellWithIndentifier:@"cell"];
    if (cell == nil ) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:identifier];
        cell.accessoryType = UITableViewCellAccessoryNone;

    return cell;
    }

}



@end

価値のあるものとして、LocationAppDelegate.h のコードとそれに続く .m

//
//  LocationAppDelegate.h
//  Location
//
//  Created by Robert Chalmers on 08/10/2013.
//  Copyright (c) 2013 Robert Chalmers. All rights reserved.
//

#import <UIKit/UIKit.h>

@class viewController;

@interface LocationAppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) viewController *viewController;
@property (strong, nonatomic) CLLocationManager *locationManager;

@end




============

//
//  LocationAppDelegate.m
//  Location
//
//  Created by Robert Chalmers on 08/10/2013.
//  Copyright (c) 2013 Robert Chalmers. All rights reserved.
//

#import "LocationAppDelegate.h"
#import "LocationViewController.h"

@implementation LocationAppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;
@synthesize locationManager = _locationManager;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    if ([CLLocationManager locationServicesEnabled]) {
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.delegate = self;
        self.locationManager.distanceFilter = 1000;
        [self.locationManager startUpdatingLocation];
    }

    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)locationManager:(CLLocationManager *)manager
                         didUpdateToLocation:(CLLocation *)newLocation
                          fromLocation:(CLLocation *)oldLocation {
                              NSLog(@"Location: %@", [newLocation description]);
                          }

- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error {
    NSLog(@"Error: %@", [error description]);
}




@end

もちろん、ほとんどの場合、そのエラーが何であるかを知りたいのですが、どのファイルに何が入っているかについてのガイドラインがあれば教えてください。

ありがとう。

4

2 に答える 2

1

xcode 5 ストーリーボードのエラーを修正するには、これを調べる必要があると思います。

エラーに関しては、次を試してください。

[tv dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

それ以外の:

[tv dequeueReusableCellWithIndentifier:@"cell"];
于 2013-10-09T10:21:37.573 に答える
0

ここであなたの答えを見つけることができます Xcode 5のiOS7ストーリーボードは垂直方向に成長し続けます

  • Xcode がストーリーボードを変更する前にコードのバージョンをコミットする

    • ストーリーボードをクリックします。Xcode は、アップグレードするかどうかを尋ねます。

    • 常にアップグレードを選択

    • この状態で、ストーリーボードはすでに Xcode によって台無しにされています。心配するな。プロジェクトを閉じるだけです。

    • 「git stash」を実行し、上記のステップ 0 でコミットしたバージョンに戻ります

    • プロジェクトを再度開きます。
于 2013-10-09T10:18:38.097 に答える