2013-09-30 128 views
0

我正在为CodeSchool做一个项目,它需要你从AFNetworking数据库导入信息。我已经完成了所有这些,并且在我的代码中没有错误,但是当我调试它并单击ProfileViewController时,我得到线程1信号SIGABRT。线程1信号SIGABRT

这里是在ProfileViewController.m代码:

#import "ProfileViewController.h" 
#import "UIKit+AFNetworking/UIImageView+AFNetworking.h" 

@interface ProfileViewController() 

@end 

@implementation ProfileViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    self.title = @"Profile"; 
    self.tabBarItem.image = [UIImage imageNamed:@"tab_icon_profile"]; 
} 
return self; 
} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
self.scrollView =[[UIScrollView alloc] initWithFrame:self.view.bounds]; 
self.scrollView.contentSize = CGSizeMake(320, 480); 
self.scrollView.autoresizingMask = (UIViewAutoresizingFlexibleHeight| UIViewAutoresizingFlexibleWidth); 

self.view.backgroundColor = [UIColor darkGrayColor]; 

UIImageView *bigBirdView = [[UIImageView alloc] init]; 
bigBirdView.frame = CGRectMake(20, 20, 100, 114); 
[bigBirdView setImageWithURL:[NSURL URLWithString:@"http://images3.wikia.nocookie.net/__cb20100901224145/muppet/images/f/f8/Big-bird-NEW.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 
[self.scrollView addSubview:bigBirdView]; 

UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 140, 280, 40)]; 
[nameLabel setBackgroundColor:[UIColor clearColor]]; 
[nameLabel setTextColor:[UIColor whiteColor]]; 
nameLabel.text = @"Name: Big Bird"; 
[self.scrollView addSubview:nameLabel]; 

UILabel *cityLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 200, 280, 40)]; 
[cityLabel setBackgroundColor:[UIColor clearColor]]; 
[cityLabel setTextColor:[UIColor whiteColor]]; 
cityLabel.text = @"From: Sesame Street"; 
[self.scrollView addSubview:cityLabel]; 

UITextView *biography= [[UITextView alloc] initWithFrame:CGRectMake(12, 260, 200, 200)]; 
[biography setBackgroundColor:[UIColor clearColor]]; 
biography.font = [UIFont fontWithName:@"Helvetica" size:15]; 
[biography setTextColor:[UIColor whiteColor]]; 
biography.editable = NO; 
biography.text = @"Big Bird likes long walks on the beach, hanging with friends, and singing songs about various subjects. Big Bird is also really into organic bird seed."; 
[self.scrollView addSubview:biography]; 

UILabel *memberSince = [[UILabel alloc] initWithFrame:CGRectMake(20, 400, 280, 40)]; 
[memberSince setBackgroundColor:[UIColor clearColor]]; 
[memberSince setTextColor:[UIColor whiteColor]]; 
memberSince.text = @"Member Since: 1969"; 
[self.scrollView addSubview:memberSince]; 

[self.view addSubview:self.scrollView]; 


} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

@end 

,这里是整个错误,包括对lldl的BT:

(lldb) bt 
* thread #1: tid = 0x28a71, 0x05b6fa6a libsystem_kernel.dylib`__pthread_kill + 10, queue =  'com.apple.main-thread, stop reason = signal SIGABRT 
frame #0: 0x05b6fa6a libsystem_kernel.dylib`__pthread_kill + 10 
frame #1: 0x05a2bb2f libsystem_c.dylib`pthread_kill + 101 
frame #2: 0x057b2e12 libsystem_sim_c.dylib`abort + 127 
frame #3: 0x055a69f9 libc++abi.dylib`abort_message + 105 
frame #4: 0x055c76ab libc++abi.dylib`default_terminate_handler() + 292 
frame #5: 0x014beb64 libobjc.A.dylib`_objc_terminate() + 108 
frame #6: 0x055c4f60 libc++abi.dylib`std::__terminate(void (*)()) + 14 
frame #7: 0x055c497d libc++abi.dylib`__cxa_throw + 116 
frame #8: 0x014be9cd libobjc.A.dylib`objc_exception_throw + 323 
frame #9: 0x023fd903 CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:] + 275 
frame #10: 0x0235090b CoreFoundation`___forwarding___ + 1019 
frame #11: 0x023504ee CoreFoundation`_CF_forwarding_prep_0 + 14 
frame #12: 0x0000415c InstaPhoto`-[ProfileViewController viewDidLoad](self=0x0899ef40, _cmd=0x007b1d27) + 1260 at ProfileViewController.m:39 
frame #13: 0x001379a8 UIKit`-[UIViewController loadViewIfRequired] + 696 
frame #14: 0x0015d1a5 UIKit`-[UINavigationController _layoutViewController:] + 39 
frame #15: 0x0015d6bb UIKit`-[UINavigationController _updateScrollViewFromViewController:toViewController:] + 235 
frame #16: 0x0015d7b3 UIKit`-[UINavigationController _startTransition:fromViewController:toViewController:] + 78 
frame #17: 0x0015e72c UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 645 
frame #18: 0x0015f349 UIKit`-[UINavigationController __viewWillLayoutSubviews] + 57 
frame #19: 0x0029839d UIKit`-[UILayoutContainerView layoutSubviews] + 213 
frame #20: 0x0008edd7 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355 
frame #21: 0x014d081f libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70 
frame #22: 0x029fc72a QuartzCore`-[CALayer layoutSublayers] + 148 
frame #23: 0x029f0514 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 380 
frame #24: 0x029f0380 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 26 
frame #25: 0x02958156 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 294 
frame #26: 0x029594e1 QuartzCore`CA::Transaction::commit() + 393 
frame #27: 0x02a15870 QuartzCore`+[CATransaction flush] + 52 
frame #28: 0x00040979 UIKit`_afterCACommitHandler + 131 
frame #29: 0x0232853e CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30 
frame #30: 0x0232848f CoreFoundation`__CFRunLoopDoObservers + 399 
frame #31: 0x023063b4 CoreFoundation`__CFRunLoopRun + 1076 
frame #32: 0x02305b33 CoreFoundation`CFRunLoopRunSpecific + 467 
frame #33: 0x0230594b CoreFoundation`CFRunLoopRunInMode + 123 
frame #34: 0x022bc9d7 GraphicsServices`GSEventRunModal + 192 
frame #35: 0x022bc7fe GraphicsServices`GSEventRun + 104 
frame #36: 0x0002494b UIKit`UIApplicationMain + 1225 
frame #37: 0x00001add InstaPhoto`main(argc=1, argv=0xbfffee84) + 141 at main.m:16 
(lldb) 

回答

1

你的问题是ProfileViewController.m 39行:

frame #12: 0x0000415c InstaPhoto`- [ProfileViewController viewDidLoad](self=0x0899ef40, _cmd=0x007b1d27) + 1260 at ProfileViewController.m:39 

doesNotRecognizeSelector异常被抛出:

frame #9: 0x023fd903 CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:] + 275 

...表示正在调用未实现的方法。

+0

ProfileViewController继承自实现viewDidLoad的UIViewController。自定义实现不需要由子类提供。 –

+0

那么我该如何解决这个问题?我是否需要执行viewDidLoad的自定义实现,或者是否应该重新排列或更改此代码?我非常感谢你的帮助! – user2832346

+0

您可以确认ProfileViewController.m中第39行的哪行代码?从你的示例贴出的第39行是后面的空行:[self.scrollView addSubview:bigBirdView]; –

0

我也怀疑在下面的代码,

UIImageView *bigBirdView = [[UIImageView alloc] init]; 
bigBirdView.frame = CGRectMake(20, 20, 100, 114); 
[bigBirdView setImageWithURL:[NSURL URLWithString:@"http://images3.wikia.nocookie.net/__cb20100901224145/muppet/images/f/f8/Big-bird-NEW.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 
[self.scrollView addSubview:bigBirdView]; 

月1日) - 他们是不提供的UIImageView像setImageWithURL任何方法:placeholderImage。阅读的UIImageview

2日)的文档 - 为什么你使用以下行主线程下载图像,

[bigBirdView setImageWithURL:[NSURL URLWithString:@"http://images3.wikia.nocookie.net/__cb20100901224145/muppet/images/f/f8/Big-bird-NEW.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 

下载图像使用异步委托NSURLConnection的/块法耶使用GCD。