我正在爲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)
ProfileViewController繼承自實現viewDidLoad的UIViewController。自定義實現不需要由子類提供。 –
那麼我該如何解決這個問題?我是否需要執行viewDidLoad的自定義實現,或者是否應該重新排列或更改此代碼?我非常感謝你的幫助! – user2832346
您可以確認ProfileViewController.m中第39行的哪行代碼?從你的示例貼出的第39行是後面的空行:[self.scrollView addSubview:bigBirdView]; –