calloutAccessoryControlTapped法(图形页面)的标签栏应用程序导致崩溃(switchViews) [英] calloutAccessoryControlTapped method (MapView) in Tab Bar Application Causes Crash (switchViews)

查看:368
本文介绍了calloutAccessoryControlTapped法(图形页面)的标签栏应用程序导致崩溃(switchViews)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个标签栏应用程序,有一个图形页面设置的标签之一。

I am building a Tab Bar App and have a MapView set up on one of the tabs.

我从工作完全这么一个基于视图的应用程序在转换这个我知道,它主要是设置正确。

I've converted this over from a View-Based Application which worked perfectly so I know that it's mostly set up correctly.

在地图上的每个pre-放置引脚有注释和链接到一个DetailViewController leftCalloutAccessoryView。我要的是标注屏幕(详细信息视图控制器)在同一选项卡可以显示出来,但是当我在左边标注按钮单击该程序崩溃。

Each pre-placed pin on the Map has annotations and a leftCalloutAccessoryView that links to the DetailViewController. What I want is for the callout screen (Detail View Controller) to just show up in that same tab but when I click on the left callout button the program crashes.

我使用触摸标注附件的方法是这样的:

The method I'm using for touching the Callout Accessory is this:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
calloutAccessoryControlTapped:(UIControl *)control
{
    MillersLocations *annotationTapped = (MillersLocations *)view.annotation;

    NSLog(@"button clicked on annotation %@", annotationTapped);

    LocationsViewController *thisMap = (LocationsViewController *)[[UIApplication sharedApplication] delegate];
    DetailViewController *dvc = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];

    dvc.title = view.annotation.title;
    dvc.addressString = view.annotation.subtitle;

    [thisMap switchViews:self.view toView:dvc.view]; //This is the line with the error message
}

在该行[thisMap switchViews:self.view toView:dvc.view];我得到一个SIGABRT错误。而错误:

On the line '[thisMap switchViews:self.view toView:dvc.view];' I get a SIGABRT error. And the errors:

2011-10-25 14:11:11.465 Miller Tab Bar[56230:207] -[Miller_Tab_BarAppDelegate switchViews:toView:]: unrecognized selector sent to instance 0x5835530
2011-10-25 14:11:11.467 Miller Tab Bar[56230:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Miller_Tab_BarAppDelegate switchViews:toView:]: unrecognized selector sent to instance 0x5835530'

是switchViews方法无效在标签栏的应用程序?如果是这样,有什么方法在标签栏的应用程序通常用于特定选项卡中切换视图?感谢您的帮助,我还在学习!

Is the switchViews method invalid in a Tab Bar app? If so, what method is generally used in a Tab Bar app to switch views within a certain tab? Thanks for the help, I'm still learning!

我意识到我是打电话来self.view',所以这里是如何我已经更新了code。我曾LocationsViewController设置,因为复制和粘贴错误委托:

I realized I'm calling it to 'self.view' so here's how I've updated the code. I had LocationsViewController set as the delegate because of copy and paste error.:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    MillersLocations *annotationTapped = (MillersLocations *)view.annotation;

    NSLog(@"button clicked on annotation %@", annotationTapped);

    LocationsViewController *thisMap = [[LocationsViewController alloc]initWithNibName:@"LocationsViewController" bundle:nil];
    DetailViewController *dvc = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];

    dvc.title = view.annotation.title;
    dvc.addressString = view.annotation.subtitle;

    [thisMap switchViews:self.view toView:dvc.view];
}

现在我没有得到错误,但它不切换视图。它记录了一切,但不会去任何地方。该方法在LocationsViewController.h声明和LocationsViewController.m实施。为什么不将它链接到什么?

Now I don't get the error but it doesn't switch views. It logs out and everything but doesn't go anywhere. The method is declared in LocationsViewController.h and implemented in LocationsViewController.m. Why wouldn't it be linking to anything?

推荐答案

如果标注方法是在同一个班 switchViews ,那么你就不需要/不应该T内部本身创建 LocationsViewController 的新实例。取而代之的 [thisMap switchViews ... ,它应该只是 [自switchViews ...

If the callout method is in the same class as switchViews then you don't need to / shouldn't create a new instance of LocationsViewController inside itself. Instead of [thisMap switchViews..., it should just be [self switchViews....

然而的,不正是这种方法做什么了解,我不能肯定它会做什么的预期(例如,会是什么与做self.view 传递给它 - ,它才能切换回)。

However, without knowing exactly what that method does, I can't be sure it will do what's expected (eg. what will it do with the self.view passed to it--will it be able to switch back).

只是一对夫妇的其他替代品(在许多)无论您使用的是标签栏与否是:

Just a couple of other alternatives (among many) whether you're using a tab bar or not are:


  • 显示详细信息视图作为一个模态视图控制器。这是很容易做到:

  • Show the detail view as a modal view controller. This is easily done by:

DetailViewController *dvc = [[DetailViewController alloc] init...
dvc.title = view.annotation.title;
dvc.addressString = view.annotation.subtitle;
[self presentModalViewController:dvc animated:YES];
[dvc release];

模式视图将使用被解雇 [自dismissModalViewControllerAnimated:YES];

将一个的UINavigationController 在地图选项卡, LocationsViewController 的导航控制器的根视图控制器推详细视图控制器。完成后的详细视图然后将弹出。实现这需要多一点的工作,但将允许用户使用甚至在细节视图显示在地图选项卡上的其他选项卡。

Put a UINavigationController in the maps tab and make LocationsViewController the root view controller of that navigation controller and push the detail view controller. The detail view would then be popped when done. Implementing this requires a bit more work but will allow the user to use the other tabs even while the detail view is showing on the map tab.

我建议将通过苹果的<一个href=\"http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457\"相对=nofollow>视图控制器编程指南以及他们介绍的语言:<一href=\"http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/_index.html#//apple_ref/doc/uid/TP40007594\"相对=nofollow>学习的Objective-C:入门和<一个href=\"http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html#//apple_ref/doc/uid/TP30001163\"相对=nofollow>的Objective-C编程语言。

I suggest going through Apple's View Controller Programming Guide as well as their introductions to the language: Learning Objective-C: A Primer, and The Objective-C Programming Language.

这篇关于calloutAccessoryControlTapped法(图形页面)的标签栏应用程序导致崩溃(switchViews)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆