寻找关于将 Pre-Storyboard 代码(XCode4)移动到 Storyboard 代码(XCode5)的教程 [关闭]

Posted

技术标签:

【中文标题】寻找关于将 Pre-Storyboard 代码(XCode4)移动到 Storyboard 代码(XCode5)的教程 [关闭]【英文标题】:Looking for a tutorial on moving Pre-Storyboard code (XCode4) to Storyboard code (XCode5) [closed] 【发布时间】:2013-10-09 10:00:27 【问题描述】:

我正在尝试掌握 XCode5,但大多数代码示例都是 XCode5 之前的版本。当然还有 ios7 之前的版本。主要问题是故事板。很多人想知道如何在没有 Storyboard 的情况下在 SCode5 中构建 - 但我不知道如何将 pre-storyboard 代码移动到 storyboard 代码。

例如。最优秀的书“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 文件中自动生成的代码有很多不同之处。所以尽我所能,我至少让定位服务在调试窗口中显示一个虚拟位置。

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

第一个,语义警告

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

第二个,红色的错误!标记

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

当然,大多数情况下,我想知道那个错误是什么,但如果有一些关于现在哪些文件中的内容的指南?

谢谢。

【问题讨论】:

情节提要就像所有xib的集合。您可能只需在 xib 中选择您的视图并将它们复制粘贴到情节提要。然后再次将所有连接连接到您的视图控制器。转移需要大量时间,但不会有快速的方法从 xib 转移到情节提要。 【参考方案1】:

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

关于错误,你应该尝试:

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

代替:

[tv dequeueReusableCellWithIndentifier:@"cell"];

【讨论】:

感谢大家 - 只是将教科书中的代码移动到新版本中,麻烦很多。牢记这一切,这是可以做到的,我想从现在开始我将继续使用 XCode5 和 iOS7 材料。只是不值得将旧代码迁移到新平台而头疼。 但是,您是否设法修复了错误 No visible interface for 'UITableView' declarations selector 'dequeueReusableCellWithIndentifier:' ? @罗伯特.C 是的。我做到了。只是我通常缺乏拼写能力。加上一些有人帮助我的代码。我的代码被贬值了,新代码修复了它。这就像一个词不同。难以置信。 我很高兴你修好了它。如果我的回答对你有所帮助,欢迎采纳:how to accept an answer【参考方案2】:

在这里你可以找到你的答案 iOS7 storyboard in Xcode 5 keep growing vertically

在 Xcode 更改其故事板之前提交您的代码版本

单击情节提要。 Xcode 会询问您是否要升级。

选择始终升级

在这种状态下,情节提要已经被 Xcode 弄乱了。别 担心。只需关闭项目。

执行“git stash”并返回到步骤 0 中提交的版本 以上

再次打开您的项目。

【讨论】:

以上是关于寻找关于将 Pre-Storyboard 代码(XCode4)移动到 Storyboard 代码(XCode5)的教程 [关闭]的主要内容,如果未能解决你的问题,请参考以下文章

python井字棋算法及代码

寻找一个库/框架将实时视频从 OS X 流式传输到 Wowza 服务器(RTMP)[关闭]

寻找更优雅(更少代码)的方式来比较多个dicts

JSF 2.0 与 Wicket 与 SpringMVC 3.x 的特殊要求

JAVA寻找任意元素之和最接近指定数值的程序

ThinkPHP5.1.x 反序列化