2012-07-08 138 views
0

我遵循iOS开发人员库中“您的第二个iOS应用程序”教程中的步骤,编译并在iPhone模拟器中运行。该应用程序允许我添加新的鸟类,但不允许我从Bird Sightings场景导航到Bird Sighting Detail屏幕。关于需要完成什么的任何想法。我查看了这些步骤,无法快速确定问题。感谢您的帮助和调试步骤。 (顺便说一句,我正在学习在Xcode IDE中进行调试)。到教程中的链接是http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/SecondiOSAppTutorial/GettingStarted/GettingStarted.html#//apple_ref/doc/uid/TP40011318-CH2-SW3iPhone的第二个iOS应用程序

感谢

// BirdsAppDelegate.h 
#import <UIKit/UIKit.h> 
@interface BirdsAppDelegate : UIResponder <UIApplicationDelegate> 
@property (strong, nonatomic) UIWindow *window; 
@end 

// BirdsAppDelegate.m 
#import "BirdsAppDelegate.h" 
#import "BirdSightingDataController.h" 
#import "BirdsMasterViewController.h" 

@implementation BirdsAppDelegate 

@synthesize window = _window; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; 
    BirdsMasterViewController *firstViewController = (BirdsMasterViewController *)[[navigationController viewControllers] objectAtIndex:0]; 

    BirdSightingDataController *aDataController = [[BirdSightingDataController alloc] init]; 
    firstViewController.dataController = aDataController; 
    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:. 
} 

@end 

// BirdsMasterViewController.h 
#import <UIKit/UIKit.h> 
@class BirdSightingDataController; 
@interface BirdsMasterViewController : UITableViewController 
@property (strong, nonatomic) BirdSightingDataController *dataController; 

@end 

// BirdsMasterViewController.m 
#import "BirdsMasterViewController.h" 
#import "BirdSightingDataController.h" 
#import "BirdSighting.h" 
#import "BirdsDetailViewController.h" 
#import "AddSightingViewController.h" 
@interface BirdsMasterViewController() <AddSightingViewControllerDelegate> 
@end 

@implementation BirdsMasterViewController 
@synthesize dataController = _dataController; 

- (void)awakeFromNib 
{ 
    [super awakeFromNib]; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

- (void)addSightingViewControllerDidCancel:(AddSightingViewController *)controller { 
    [self dismissViewControllerAnimated:YES completion:NULL]; 
} 

- (void)addSightingViewControllerDidFinish:(AddSightingViewController *)controller name:(NSString *)name location:(NSString *)location { 
    if ([name length] || [location length]) { 
     [self.dataController addBirdSightingWithName:name location:location]; 
     [[self tableView] reloadData]; 
    } 
    [self dismissModalViewControllerAnimated:YES]; 
} 

#pragma mark - Table View 

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [self.dataController countOfList]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"BirdSightingCell"; 

    static NSDateFormatter *formatter = nil; 
    if (formatter == nil) { 
     formatter = [[NSDateFormatter alloc] init]; 
     [formatter setDateStyle:NSDateFormatterMediumStyle]; 
    } 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    BirdSighting *sightingAtIndex = [self.dataController objectInListAtIndex:indexPath.row]; 
    [[cell textLabel] setText:sightingAtIndex.name]; 
    [[cell detailTextLabel] setText:[formatter stringFromDate:(NSDate *)sightingAtIndex.date]]; 
    return cell; 
} 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the specified item to be editable. 
    return NO; 
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([[segue identifier] isEqualToString:@"ShowSightingDetails"]) { 
     BirdsDetailViewController *detailViewController = [segue destinationViewController]; 

     detailViewController.sighting = [self.dataController objectInListAtIndex:[self.tableView indexPathForSelectedRow].row]; 
    }else if ([[segue identifier] isEqualToString:@"ShowAddSightingView"]) { 
     AddSightingViewController *addController = (AddSightingViewController *)[[[segue destinationViewController] viewControllers] objectAtIndex:0]; 
     addController.delegate = self; 
    } 
} 
@end 

// BirdsDetailViewController.h 
#import <UIKit/UIKit.h> 
@class BirdSighting; 

@interface BirdsDetailViewController : UITableViewController 

@property (strong, nonatomic) BirdSighting *sighting; 
@property (weak, nonatomic) IBOutlet UILabel *birdNameLabel; 
@property (weak, nonatomic) IBOutlet UILabel *locationLabel; 
@property (weak, nonatomic) IBOutlet UILabel *dateLabel; 

@end 


// BirdsDetailViewController.m 
#import "BirdsDetailViewController.h" 
#import "BirdSighting.h" 

@interface BirdsDetailViewController() 
- (void)configureView; 
@end 

@implementation BirdsDetailViewController 

@synthesize sighting = _sighting, birdNameLabel = _birdNameLabel, locationLabel = _locationLabel, dateLabel = _dateLabel; 

#pragma mark - Managing the detail item 
- (void)setSighting:(BirdSighting *) newSighting 
{ 
    if (_sighting != newSighting) { 
     _sighting = newSighting; 

     // Update the view. 
     [self configureView]; 
    } 
} 

- (void)configureView 
{ 
    // Update the user interface for the detail item. 
    // Update the user interface for the detail item. 
    BirdSighting *theSighting = self.sighting; 

    static NSDateFormatter *formatter = nil; 
    if (formatter == nil) { 
     formatter = [[NSDateFormatter alloc] init]; 
     [formatter setDateStyle:NSDateFormatterMediumStyle]; 
    } 
    if (theSighting) { 
     self.birdNameLabel.text = theSighting.name; 
     self.locationLabel.text = theSighting.location; 
     self.dateLabel.text = [formatter stringFromDate:(NSDate *)theSighting.date]; 
    } 
} 

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

- (void)viewDidUnload 
{ 
    self.sighting = nil; 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

@end 
+7

当问一个关于特定教程的问题时,它通常有助于链接到教程。同时发布代码也是至关重要的,因为如果我们看不到您在做什么,我们怎么能告诉您您做错了什么?另外,你问我们调试步骤的事实会给我一个红旗。在寻求帮助之前你还没有调试过? (或者,你的意思是你不知道如何使用XCode调试器,在这种情况下,你可能会将其作为一个单独的问题发布,我将非常乐意向您解释它) – WendiKidd 2012-07-08 05:15:22

+0

是的,我没有调试过试图找出在Xcode IDE中的调试。抱歉关于不给链接。教程链接是:http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/SecondiOSAppTutorial/GettingStarted/GettingStarted.html#//apple_ref/doc/uid/TP40011318-CH2-SW3 – user1509593 2012-07-08 06:03:38

+1

The链接不会显示在您的评论中。此外,你应该编辑它的问题,而不是发表评论。我问的其他问题呢? – WendiKidd 2012-07-08 06:04:30

回答

2

我也遇到了同样的问题,这里我找到了解决办法:

  1. 确保您segure(control+drag)从TableViewCell(NOT MasterViewController产生)至BirdsDetailViewController
    参考:“控制 - 从主场景中的表格单元格拖动到细节场景”,教程:Design the Detail Scene
  2. 确保您master view类设置为BirdsMasterViewController,没有违约UITableViewController,并detail view类是BirdsDetailViewController,不会违约UITableViewController
    您可以在选定的主/细节视图后在签名检查器中检查它们。
  3. 确保您的Table View Cell标识与您的BirdSightingCell中的标识相同。

详情请参阅this link

相关问题