简体   繁体   English

为什么在加载TableViewcontroller时出现此错误

[英]Why am I getting this error when loading my TableViewcontroller

I'm working on a project for iOS5 using ARC and storyboard. 我正在使用ARC和Storyboard开发iOS5项目。

I have a mapview with annotations with a disclosure button going to my DetailView (which is a TableViewController) but when it's supposed to be loaded, I get the following error: 我有一个带批注的mapview,其中的公开按钮转到我的DetailView(这是一个TableViewController),但是当应该加载它时,出现以下错误:

2012-07-18 14:09:43.328 Zone-It-new[1966:707] Loadded the view for MapViewController
2012-07-18 14:11:40.467 Zone-It-new[1966:707] -[UILabel copyWithZone:]: unrecognized selector sent to instance 0x138470
2012-07-18 14:11:40.470 Zone-It-new[1966:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel copyWithZone:]: unrecognized selector sent to instance 0x138470'
*** First throw call stack:
(0x3748488f 0x35189259 0x37487a9b 0x37486915 0x373e1650 0x311997ef 0x31195059 0x31194711 0x3119466b 0x311945e7 0x31284f63 0x311979bb 0x311973ad 0x31191b8b 0x311917d5 0x9386d 0x3120a93d 0x31284627 0x37cf5933 0x37458a33 0x37458699 0x3745726f 0x373da4a5 0x373da36d 0x33b99439 0x31186cd5 0x924b3 0x92458)
terminate called throwing an exception(lldb) 

This is my detailviewcontroller.h: 这是我的detailviewcontroller.h:

#import <UIKit/UIKit.h>
#import "Event.h"

@interface DetailViewController :  UITableViewController <UITableViewDelegate, UITableViewDataSource>{
     IBOutlet UILabel *title;
     IBOutlet UILabel *description;
     IBOutlet UILabel *zone;
     IBOutlet UILabel *gemeente;
     IBOutlet UILabel *plaats;
     IBOutlet UILabel *deelnemers;
     IBOutlet UILabel *start;
     IBOutlet UILabel *einde;
     IBOutlet UILabel *id_nr;
}

@property (nonatomic) Event *event;
@property (nonatomic) IBOutlet UILabel *title, *zone, *description, *gemeente, *deelnemers, *start, *einde, *plaats, *id_nr;
@end

part of the DetailViewController.m DetailViewController.m的一部分

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [[self navigationController] setNavigationBarHidden:NO animated:YES];


    /*title.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;*/
    [title lineBreakMode];
    [title setText:[event title]];
    [title sizeToFit];

    gemeente.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
    [title lineBreakMode];
    [gemeente setText:[event gemeente]];
}

And this is where the view gets created in via the ListView: 这是通过ListView在其中创建视图的地方:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"detail"];
    SingletonManager *sharedManager = [SingletonManager sharedManager];

    [detail setEvent:[sharedManager.eventsManager objectAtIndex:indexPath.row]];

    [self.navigationController pushViewController:detail animated:YES];
}

Event.h Event.h

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

@interface Event : NSObject <MKAnnotation>


// required property from mkanotation
@property (nonatomic) CLLocationCoordinate2D coordinate;

// Optional
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *description;
@property (nonatomic, copy) NSString *zone;
@property (nonatomic, assign) NSString *gemeente;
@property (nonatomic, copy) NSString *straat;
@property (nonatomic, assign) int deelnemers;
@property (nonatomic, copy) NSDate *start;
@property (nonatomic, copy) NSDate *einde;
@property (nonatomic, copy) NSString *plaats;
@property (nonatomic, readonly) int id_nr;
@property (nonatomic, assign) int huisnummer;



@end

----- Some more debugging information ------- -----更多调试信息-------

While using the exception breakpoints it stopped here: 使用异常断点时,它在这里停止:

[self.navigationController pushViewController:detail animated:YES];

console: 安慰:

2012-07-18 15:53:46.691 Zone-It-new[179:707] Loadded the view for MapViewController 
2012-07-18 15:54:01.940 Zone-It-new[179:707] -[UILabel copyWithZone:]: unrecognized selector sent to instance 0x170bb0 
(lldb)

It appears that somewhere in your code you're trying to copy a UILabel. 似乎您的代码中的某处您正在尝试复制UILabel。 UIView subclasses don't adhere to the NSCopying protocol, so trying to copy any UIView will result in an exception (unless it's a subclass that does implements the protocol). UIView子类不遵循NSCopying协议,因此尝试复制任何UIView都会导致异常(除非它是实现该协议的子类)。 I'd search through your code base to check where the copy is occurring. 我会在您的代码库中进行搜索,以检查复制发生的位置。 If you can't find any place that explicitly copies the UILabel, check collection classes. 如果找不到任何明确复制UILabel的位置,请检查集合类。 Some collections classes will copy values in (NSDictionary does this with keys, so if you're trying to use a UILabel as a key for a NSDictionary, you'll get the error). 某些集合类将复制值(NSDictionary使用键进行此操作,因此,如果您尝试将UILabel用作NSDictionary的键,则会收到错误)。 Also check your properties. 还要检查您的属性。 What you show in your displayed code is fine, but if you specify a copy in a protocol for a UILabel, that'll also give the error. 您在显示的代码中显示的内容很好,但是,如果您在UILabel的协议中指定了copy ,则也会出现此错误。

You should also try standard debugging techniques like setting a breakpoint for all exceptions. 您还应该尝试标准的调试技术,例如为所有异常设置断点。 (go to the breakpoints nav pane, at the bottom click the plus sign). (转到断点导航窗格,在底部单击加号)。 This should help you find the problem by breaking on your offending line of code. 这应该可以通过中断令人讨厌的代码行来帮助您找到问题。 Just be aware that if the copying is occurring in Apple's code (like setting a NSDictionary key) the breakpoint might not break on your code. 请注意,如果复制是以Apple的代码进行的(例如设置NSDictionary密钥),则断点可能不会在您的代码上中断。

Update 更新

Given your new code, I would suggest trying the following: 给定您的新代码,我建议尝试以下操作:

  1. Try to find any place in your code where "anything" is copied. 尝试在代码中找到复制“任何内容”的任何位置。 Obviously your not explicitly copying UILabel but maybe you're accidentally copying it by passing the wrong argument somewhere. 显然,您没有显式复制UILabel,但可能是由于在某个地方传递了错误的参数而意外地复制了它。 For example: Remove all copy keywords from your Event properties and test it again. 例如:从事件属性中删除所有copy关键字,然后再次进行测试。 You probably don't need to specify copy for NSString anyway, but what we're doing here is making sure you're not accidentally setting a UILabel to one of those properties. 无论如何,您可能都不需要为NSString指定copy ,但是我们在这里要做的是确保您不会意外地将UILabel设置为这些属性之一。 If the code doesn't break, you didn't fix it but now you know what the problem is (trying to assign a UILabel to the wrong property). 如果代码没有中断,则您没有修复它,但是现在您知道了问题所在(尝试将UILabel分配给错误的属性)。
  2. Start commenting out various blocks of code, one at a time, to find the problem. 开始注释掉各种代码块,一次注释一次,以发现问题。 For example, comment out your entire viewDidLoad method and test your code. 例如,注释掉整个viewDidLoad方法并测试代码。 If it works, you know the problem is in there. 如果有效,则说明问题出在那儿。 So uncomment part of the method and test again. 因此取消注释该方法的一部分并再次测试。 Keep repeating until you've narrowed down the problem. 不断重复,直到您缩小问题的范围为止。 If it still breaks with viewDidLoad , uncomment that and try a different block of code. 如果仍然无法通过viewDidLoad中断,请取消注释并尝试其他代码块。 In essence, you're playing detective to try to find the offending line of code. 本质上,您是在扮演侦探,试图找到令人讨厌的代码行。

The fix for this is to rename the title property in the UIViewController . 解决此问题的方法是重命名UIViewControllertitle属性。 This is due to the fact that UIViewController already defines an NSString * property with a name of title . 这是由于UIViewController已经定义了一个名称为titleNSString *属性。

This can often mean you're trying to assign an object to a method that can't handle it, rather than a property of that object. 这通常可能意味着您试图将对象分配给无法处理的方法,而不是该对象的属性。 For example, trying to set a UILabel to an object rather than a string property on that object. 例如,尝试将UILabel设置为对象,而不是该对象的字符串属性。

My guess is it's this line: [gemeente setText:[event gemeente]]; 我的猜测是这行: [gemeente setText:[event gemeente]];

There could also be an issue here: 这里也可能存在问题:

@property (nonatomic) Event *event;

You haven't set Event *event as an instance variable but are referencing it as one. 您尚未将Event *event设置为实例变量,但将其作为一个实例引用。 Try self.event for accessing event as you have it above. 尝试使用self.event访问事件,因为上面有它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决此错误“尝试对程序包进行身份验证时发生错误:397613980.itmsp”? 我在加载我的应用程序时 - how to resolve this error“An error occurred while trying to authenticate the package: 397613980.itmsp”? I am getting when loading my application NSFetchedResultsController-我的_sectionNameKeyPath_是_nil_! 为什么添加/删除时出现此错误? - NSFetchedResultsController - My _sectionNameKeyPath_ is _nil_ !! Why am I getting this error when adding / deleting? 加载TableViewController时出现NSInvalidArgumentException - NSInvalidArgumentException when loading a TableViewController 保存NSManagedObjectContext这个'干净'时为什么会出现合并错误? - Why am I getting a merge error when saving an NSManagedObjectContext this 'clean'? iPhone-当视图映射正确时,为什么会出现此错误? - iPhone - Why am I getting this error when the view mapping is correct? 当我从其他应用程序向我的应用程序添加文件夹时出现错误,例如没有此类文件或目录 - when i am adding folder from other app to my app am getting error like no such file or directory 为什么我会收到此 NSManaged Object 错误 - Why Am I Getting This NSManaged Object Error 为什么在iOS加载屏幕后出现空白? - Why am I getting a blank slate after the iOS loading screen? 为什么我会收到sqlite3error? - Why I am getting sqlite3error? 当我发送到许多请求时,为什么会出现此错误(HTTP错误400)? - Why i am getting this error (HTTP error 400.) when I send to many request?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM