首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >寻找关于将前故事板代码(XCode4)移动到故事板代码(XCode5)的教程。

寻找关于将前故事板代码(XCode4)移动到故事板代码(XCode5)的教程。
EN

Stack Overflow用户
提问于 2013-10-09 10:00:27
回答 2查看 139关注 0票数 0

我正试图掌握XCode5,但大多数代码示例都是XCode5 5之前的代码。当然,在iOS7之前。主要问题是故事板。很多人想知道如何在没有故事板的情况下在SCode5中构建--但我不知道如何将前故事板代码转换为故事板代码。

例如。最优秀的书,“地理定位在iOS”阿拉斯代尔艾伦,O‘’Reilly,2012年,是充满了几个版本前编写的代码。当然,当我在XCode 5/iOS7 7级别进入XCode时,我不知道他们在各个部分都在谈论什么。我的示例代码已经开始工作了,但是它现在正在抛出一个错误,我无法理解它。我怀疑是因为它试图用Code4的方式来做,而我现在在XCode5。

不管怎么说-最好的是一个教程,指出一个改变。让我举个例子:书中第一个例子的代码是这样的。

在书中的映像中,它显示了

代码语言:javascript
复制
LocationAppDelegate.h
LocationAppDelegate.m
LocationViewController.h
LocationViewController.
LocationViewController.xib

在我的显示器里,我有所有相同的文件,除了。而不是".xib“文件,而是"Main.storyboard”

到目前为止,我相信,从我所读到的,Main.storyboard是xib文件的新等价物。但是,在.h和.m文件中自动生成的代码有很多不同之处。因此,我已经尽了最大努力,至少让location服务在调试窗口中显示一个虚拟位置。

但是-现在我有了这个错误。实际上有两个错误。

第一,语义警告

代码语言:javascript
复制
LocationViewController.m:15:17: Method 'tableView:cellForRowAtIndexPath:' in protocol not implemented

的第二,一个错误与红色!马克

代码语言:javascript
复制
LocationViewController.m:60:9: No visible @interface for 'UITableView' declares the selector 'dequeueReusableCellWithIndentifier:'

书中所显示的代码是相当直接的,但是这个错误使我失去了方向。

来自LocationViewController.m的代码

代码语言:javascript
复制
//
//  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的代码

代码语言:javascript
复制
//
//  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

代码语言:javascript
复制
//
//  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

当然,大多数情况下,我想知道错误是什么,但是对于哪些文件现在是什么,是否有一些指导方针?

谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-10-09 10:18:38

在这里你可以找到你的答案,Xcode 5中的iOS7故事板保持垂直增长

  • 在Xcode更改故事板之前提交代码的版本
代码语言:javascript
复制
- Click on the storyboard. Xcode will ask if you want to upgrade.
- Choose the always upgrade
- At this state the storyboard is already messed up by Xcode. don't worry. just close the project.
- Do a "git stash" and go back to the version to committed in step 0 above
- Open your project again.

票数 0
EN

Stack Overflow用户

发布于 2013-10-09 10:21:37

我认为您应该看看来修复xcode 5故事板错误。

关于错误,您应该尝试:

代码语言:javascript
复制
[tv dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

而不是:

代码语言:javascript
复制
[tv dequeueReusableCellWithIndentifier:@"cell"];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19268840

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档