2012-03-17 7 views
15

간단한 RSS 응용 프로그램을 만들고 있는데 Objective-c가 좋지 않습니다. 응용 프로그램은 항상 성공적으로 빌드하고 아무런 오류나 경고가 없습니다, UITableView에서 RSS를 읽습니다. 언제든지 셀을 끝내고 main.m에서이 줄은 "줄 1 : 신호 SIGABRT"이 줄에 올 것입니다. :Xcode 오류 - 스레드 1 : signal SIGABRT

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 

내 응용 프로그램의 정보 :

이 앱은 엑스 코드 버전에 의해 만들어집니다 : 앱은 아이폰과 맥북의 "마스터 - 세부 응용 프로그램"템플릿에서 생성 된 4.3.1 . 내가 사용하고 디버거가 LLDB하고 내 아이폰 시뮬레이터 내가 여기

스토리 보드

를 사용하고 5.1 인 Main.m입니다 :

#import <UIKit/UIKit.h> 

#import "AppDelegate.h" 

int main(int argc, char *argv[]) 
{ 

    @autoreleasepool { 
     return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 
    } 
} 

AppDelegate.h은 다음과 같습니다

#import <UIKit/UIKit.h> 

@interface AppDelegate : NSObject <UIApplicationDelegate> { 

    UIWindow *window; 
    UINavigationController *navigationController; 
} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 

@end 

내 AppDelegate.m은 다음과 같습니다 :

#import "AppDelegate.h" 




#import "AppDelegate.h" 
#import "MasterViewController.h" 


@implementation AppDelegate 

@synthesize window; 
@synthesize navigationController; 


#pragma mark - 
#pragma mark Application lifecycle 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    // Override point for customization after app launch  

    [window addSubview:[navigationController view]]; 
    [window makeKeyAndVisible]; 
    return YES; 
} 


- (void)applicationWillTerminate:(UIApplication *)application { 
    // Save data if appropriate 
} 


#pragma mark - 
#pragma mark Memory management 

- (void)dealloc { 
    [navigationController release]; 
    [window release]; 
    [super dealloc]; 
} 


@end 

이것은 유일한 메시지 :

-(void)fetchRss 
{ 
    NSLog(@"fetch rss"); 
    NSData* xmlData = [[NSMutableData alloc] initWithContentsOfURL:[NSURL URLWithString: kRSSUrl] ]; 
    NSError *error; 

    GDataXMLDocument* doc = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&error]; 

    if (doc != nil) { 
     self.loaded = YES; 

     GDataXMLNode* title = [[[doc rootElement] nodesForXPath:@"channel/title" error:&error] objectAtIndex:0]; 
     [self.delegate updatedFeedTitle: [title stringValue] ]; 

     NSArray* items = [[doc rootElement] nodesForXPath:@"channel/item" error:&error]; 
     NSMutableArray* rssItems = [NSMutableArray arrayWithCapacity:[items count] ]; 

     for (GDataXMLElement* xmlItem in items) { 
      [rssItems addObject: [self getItemFromXmlElement:xmlItem] ]; 
     } 

     [self.delegate performSelectorOnMainThread:@selector(updatedFeedWithRSS:) withObject:rssItems waitUntilDone:YES]; 
    } else { 
     [self.delegate performSelectorOnMainThread:@selector(failedFeedUpdateWithError:) withObject:error waitUntilDone:YES]; 
    } 

    [doc autorelease]; 
    [xmlData release]; 
} 

MasterViewController.h :

#import <UIKit/UIKit.h> 
#import "RSSLoader.h" 
#import "DetailViewController.h" 


@interface MasterViewController : UITableViewController<RSSLoaderDelegate> { 

    RSSLoader* rss; 
    NSMutableArray* rssItems; 

} 



@end 

MasterViewController.m :

#import "MasterViewController.h" 

#import "DetailViewController.h" 




@implementation MasterViewController 

#pragma mark - 
#pragma mark View lifecycle 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.navigationItem.title = @"RAHNAVARD"; 
    self.navigationItem.prompt = @"LATEST NEWS"; 
    rssItems = nil; 
    rss = nil; 

    self.tableView.backgroundColor = [UIColor whiteColor]; 
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; 
    [self.tableView setIndicatorStyle:UIScrollViewIndicatorStyleWhite]; 

    //self.tableView.tableHeaderView = [[TableHeaderView alloc] initWithText:@"fetching rss feed"]; 

} 

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 

} 

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 

    if (rss==nil) { 
     rss = [[RSSLoader alloc] init]; 
     rss.delegate = self; 
     [rss load]; 
    } 
} 

/* 
- (void)viewWillDisappear:(BOOL)animated { 
[super viewWillDisappear:animated]; 
} 
*/ 
/* 
- (void)viewDidDisappear:(BOOL)animated { 
[super viewDidDisappear:animated]; 
} 
*/ 

/* 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations. 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
*/ 


#pragma mark - 
#pragma mark Table view data source 

// Customize the number of sections in the table view. 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 


// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    if (rss.loaded == YES) { 
     return [rssItems count]*2; 
    } else { 
     return 1; 
    } 
} 

- (UITableViewCell *)getLoadingTableCellWithTableView:(UITableView *)tableView 
{ 
    static NSString *LoadingCellIdentifier = @"LoadingCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LoadingCellIdentifier]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:LoadingCellIdentifier] autorelease]; 
    } 

    cell.textLabel.text = @"Loading..."; 

    UIActivityIndicatorView* activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
    [activity startAnimating]; 
    [cell setAccessoryView: activity]; 
    [activity release]; 

    return cell; 
} 

- (UITableViewCell *)getTextCellWithTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath { 
    static NSString *TextCellIdentifier = @"TextCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TextCellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:TextCellIdentifier] autorelease]; 
    } 

    NSDictionary* item = [rssItems objectAtIndex: (indexPath.row-1)/2]; 

    //article preview 
    cell.textLabel.font = [UIFont systemFontOfSize:11]; 
    cell.textLabel.numberOfLines = 3; 
    cell.textLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7]; 
    cell.backgroundColor = [UIColor clearColor]; 
    cell.textLabel.backgroundColor = [UIColor clearColor]; 

    UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 
    backView.backgroundColor = [UIColor clearColor]; 
    cell.backgroundView = backView; 

    CGRect f = cell.textLabel.frame; 
    [cell.textLabel setFrame: CGRectMake(f.origin.x+15, f.origin.y, f.size.width-15, f.size.height)]; 
    cell.textLabel.text = [item objectForKey:@"description"]; 

    return cell; 
} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    if (rss.loaded == NO) { 
     return [self getLoadingTableCellWithTableView:tableView]; 
    } 

    if (indexPath.row % 2 == 1) { 
     return [self getTextCellWithTableView:tableView atIndexPath:indexPath]; 
    } 

    static NSString *CellIdentifier = @"TitleCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 
    backView.backgroundColor = [UIColor clearColor]; 
    cell.backgroundView = backView; 

    NSDictionary* item = [rssItems objectAtIndex: indexPath.row/2]; 

    cell.textLabel.text = [item objectForKey:@"title"]; 

    return cell; 
} 



/* 
// Override to support conditional editing of the table view. 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
// Return NO if you do not want the specified item to be editable. 
return YES; 
} 
*/ 


/* 
// Override to support editing the table view. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

if (editingStyle == UITableViewCellEditingStyleDelete) { 
// Delete the row from the data source. 
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
} 
else if (editingStyle == UITableViewCellEditingStyleInsert) { 
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 
} 
} 
*/ 


/* 
// Override to support rearranging the table view. 
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { 
} 
*/ 


/* 
// Override to support conditional rearranging of the table view. 
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { 
// Return NO if you do not want the item to be re-orderable. 
return YES; 
} 
*/ 


#pragma mark - 
#pragma mark Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [tableView deselectRowAtIndexPath:indexPath animated:NO]; 

    //DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; 
    DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; 
    detailViewController.item = [rssItems objectAtIndex:floor(indexPath.row/2)]; 
    [self.navigationController pushViewController:detailViewController animated:YES]; 
    [detailViewController release]; 
} 


#pragma mark - 
#pragma mark Memory management 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Relinquish ownership any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. 
    // For example: self.myOutlet = nil; 
} 


- (void)dealloc { 
    [rssItems release]; 
    rssItems = nil; 

    [rss release]; 
    rss = nil; 

    [super dealloc]; 
} 

#pragma mark - 
#pragma mark RSSLoaderDelegate 
-(void)updatedFeedWithRSS:(NSMutableArray*)items 
{ 
    rssItems = [items retain]; 
    [self.tableView reloadData]; 
} 

-(void)failedFeedUpdateWithError:(NSError *)error 
{ 
    // 
} 

@end 

는 당신이 더 많은 것을 원하는 경우에 여기에

2012-03-17 17:32:29.498 Rahnavard[1862:12e03] fetch rss 
2012-03-17 17:33:01.212 Rahnavard[1862:f803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/hassantavari/Library/Application Support/iPhone Simulator/5.1/Applications/48090189-E17C-40CF-9BF1-ACA18FC0B02B/Rahnavard.app> (loaded)' with name 'DetailViewController'' 
*** First throw call stack: 
(0x16e4022 0x1875cd6 0x168ca48 0x168c9b9 0x366638 0x20c1fc 0x20c779 0x20c99b 0x20cd11 0x21e8fd 0x21eaef 0x21edbb 0x21f85f 0x21fe06 0x21fa24 0x393c 0x1d65c5 0x1d67fa 0xa6b85d 0x16b8936 0x16b83d7 0x161b790 0x161ad84 0x161ac9b 0x15cd7d8 0x15cd88a 0x145626 0x26a2 0x2615) 
terminate called throwing an exception(lldb) 

는 페치 RSS했다 정보는 나에게 그것을 말한다. 답을하면 내 질문을 편집하고 대답을 편집 할 것입니다.

정말 감사드립니다.

+6

SIGABRT는 예외가 트리거되었음을 의미합니다. 콘솔 로그는 정확한 예외 메시지를 출력 할 것이고 그것을보아야합니다 (여기에 게시하십시오). – DarkDust

+1

이봐, Xcode 프로젝트 파일과 xib XML 파일을 추가하는 것을 잊어 버렸다. – Abizern

답변

9

DetailViewController이라는 XIB를로드하려고하지만 XIB가 없거나 현재 대상의 멤버가 아닙니다.

+1

이 답변에 추가하려면 Ctrl 키를 누른 다음 콘센트를 제거하십시오. 그것은 내 코드에 아무데도 없었고, 내가 삭제할 수있는 유일한 방법입니다. 제품> 깨끗하게 처리되지 않았습니다. – William

9

SIGABRT는 일반적으로 포착되지 않는 예외가 있음을 의미합니다. 콘솔에 대한 자세한 정보가 있어야합니다.

0

SIGABRT는 다른 답변에서 언급했듯이 일반적으로 포착되지 않는 예외입니다. Objective-C에 대해 조금 더 배워야합니다. 문제는 아마도 UITableViewDelegate 메서드 didSelectRowAtIndexPath에 있습니다. 당신이 우리에게 당신이 테이블 데이터 소스 및 위임 방법을 처리하는 코드의 무언가를 보여줄 때까지

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

난 당신에게 더 많은 것을 말할 수 없다.

+0

어떻게하면 NIB를로드 할 수 없다는 예외에 대해 이야기 할 때 문제를 일으키는 테이블 뷰라고 생각합니까? – DarkDust

+1

테이블 뷰 셀을 탭하면 이러한 현상이 발생합니다.그러나 한 가지 더 알아 보았습니다. 정확히 새 View Controller를 어떻게 제시하고 있습니까? 번들을 지정할 필요가 있다면 [NSBundle mainBundle]이 있는지 확인하십시오. 또한 컴파일 및 빌드시 오류가 발생할 수 있습니다. XIB에 올바른 대상이 있는지 확인하고 청소 (Command + Shift + K) 및 정리 (Command + Shift + Alt + K)를 시도하십시오. 코드의 일부를보고 rss를 가져 와서 처리 할 수 ​​있다면 좋을 것입니다. (적어도 일부분) –

관련 문제