0

我正在为 CodeSchool 做一个项目,它要求您从 AFNetworking 数据库中导入信息。我已经完成了所有这些,并且我的代码中没有错误,但是当我调试它并单击 ProfileViewController 时,我得到了线程 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) 
4

2 回答 2

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

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

于 2013-09-30T19:11:41.653 回答
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];

1st)- 它们不是 UIImageview 中可用的任何方法,如 setImageWithURL:placeholderImage。阅读 UIImageview的文档

2nd) - 为什么您使用以下行在主线程上下载图像,

[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。

于 2013-09-30T19:17:43.367 回答