2013-10-09 46 views
0

我試圖去掌握XCode5,但大多數代碼示例都是XCode5之前版本。當然還有iOS7之前。主要問題是故事板。許多人希望知道如何在沒有Storyboard的情況下在SCode5中構建 - 但我不知道如何將預故事板代碼移動到故事板代碼。尋找關於將Pre-Storyboard代碼(XCode4)移動到Storyboard代碼(XCode5)的教程

例如。最出色的書「iOS中的地理位置」,Alasdair Allan,O'Reilly,2012年,充滿了幾個版本之前編寫的代碼。當然,當我在XCode5/iOS7級別進入XCode時,我不知道他們在各個部分討論了什麼。 我有種示例代碼工作的開始,但現在拋出一個錯誤,我無法弄清楚。我懷疑是因爲它試圖做到Code4的方式,而我在XCode5中。

無論如何 - 最好的教程是指出一個變化。 讓我舉個例子: 本書第一個例子的代碼是這樣的。

在書中的項目瀏覽圖片,它顯示

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

在我的顯示器,我都相同的文件除外。而不是「.xib」文件我有「Main.storyboard」

到目前爲止確定 - 我相信從我所讀到的,Main.storyboard是xib文件的新equivelant。 但是.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 

當然,大多數情況下,我想知道那個錯誤是什麼,但是如果有什麼指導原則可以指出什麼文件在進行什麼操作?

謝謝。

+0

,故事情節是像所有xibs的集合。你可能只需要在你的xib裏面選擇你的視圖並複製粘貼到故事板。然後再將所有連接連接到您的viewcontroller。轉移花費了大量的時間,但是不會有快速的方式從xib轉移到故事板。 –

回答

0

在這裏你可以找到答案 iOS7 storyboard in Xcode 5 keep growing vertically

  • 提交一個版本的代碼的Xcode改變其情節串連圖板

    • 單擊情節串連圖板前。 Xcode會問你是否要升級。

    • 選擇隨時升級

    • 在這種狀態下,故事板是由Xcode中已經搞砸了。不要 擔心。只需關閉該項目。

    • 做一個「混帳藏匿」,並回到版本致力於在步驟0 上述

    • 再次打開項目。
1

我想你應該看看到this修復的Xcode 5分鏡腳本錯誤。

至於錯誤,你應該嘗試:

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

相反的:

[tv dequeueReusableCellWithIndentifier:@"cell"]; 
+0

**向所有人致謝** - 僅僅爲了將文本書中的代碼移動到新版本而帶來的麻煩很多。牢記這一點,可以做到這一點,我想我會留在XCode5和iOS7的材料中。只是不值得頭疼的嘗試將舊代碼移動到新平臺。 –

+0

但是,您是否設法解決錯誤_無可見接口爲'UITableView'聲明選擇器'dequeueReusableCellWithIndentifier:'_? @ Robert.C – Brams

+1

是的。我做到了。只是我平時缺乏拼寫能力。加上有人幫助我的代碼。我的代碼被折舊了,新的代碼修復了它。這就像一個字不同。難以置信的。 –