該應用程序非常簡單,一個導航到tableview的nevigationviewcontroller。 但當i'm訪問到langsarray,它崩潰訪問UITableView中的變量崩潰我的應用程序
下面是相關代碼:
MenuViewController.m
-(void) Settings{
TestViewController *testvc = [[TestViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController setNavigationBarHidden:NO animated:NO];
[self.navigationController pushViewController:testvc animated:YES];
[testvc release];
}
#import <UIKit/UIKit.h>
@interface TestViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
NSArray *langsarray;
}
@property (nonatomic, retain) NSArray *langsarray;
@end
#import "TestViewController.h"
@implementation TestViewController
@synthesize langsarray;
- (void)loadView {
//Create the table
UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
tableView.delegate = self;
tableView.dataSource = self;
[tableView reloadData];
self.view = tableView;
//read the info
NSString *path = [[NSBundle mainBundle] pathForResource:@"l" ofType:@"txt"];
NSString *langs = [[NSString alloc]initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
langsarray = [langs componentsSeparatedByString: @"\n"];
[path release];
[langs release];
[tableView release];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//Accessing langsarray crash the app
//harcoded works fine: return 5;
return [langsarray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
// again, accessing langsarray crash the app
cell.textLabel.text = [[[langsarray objectAtIndex:row] componentsSeparatedByString:@"="] objectAtIndex:0];
cell.detailTextLabel.text = [[[langsarray objectAtIndex:row] componentsSeparatedByString:@"="] objectAtIndex:1];
return cell;
}
這是
計劃接收信號輸出: 「EXC_BAD_ACCESS」。警告:無法 找到 「_sigtramp」 最小符號 - 回溯可能是不可靠的殺
的Xcode 3.1.4 豹
感謝您的幫助,但它doesn't工作。 我把self.langsarray = [langs componentsSeparatedByString:@「\ n」]; inOfRowsInSection crash: return [self.langsarray count]; return [langsarray count];在兩種情況下都會發生碰撞。 – gerardp 2010-01-18 11:24:18