2012-03-20 12 views
1

私はXcodeとObjective-Cのプログラミングには新しく、助けが必要です。xcode配列とUITableViewの配列

私は、階層データと2つの別々のUITableViewsを使用するiOS用の基本プログラムを作成したいと考えています。 2番目のUITableViewには、最初のUITableViewで選択されたセル/行に基づいて、viewControllersの間で渡される配列が挿入されます。

プログラムをコンパイルしますが、プログラムを実行するときにSIGABRTエラーが発生します。誰かがSIGABRTを修正し、mainArrayを2番目のtableViewに渡すのを助けることができますか?

ここまでは私がどれだけ得たかです。

マイコード:

ArrayTableViewController.h

@interface arrayTableViewController : UITableViewController 
@property (nonatomic, strong) NSMutableArray *mainArray; 
@property (nonatomic, strong) NSMutableArray *secondArray; 
@property (nonatomic, strong) NSMutableArray *thirdArray; 
@end 

ArrayTableViewController.m

#import "ArrayTableViewController.h" 
#import "table2.h" 
@implementation arrayTableViewController 
@synthesize mainArray, secondArray, thirdArray; 

-(void) viewDidLoad { 
[super viewDidLoad]; 
mainArray = [[NSMutableArray alloc] initWithObjects: secondArray,  thirdArray, nil]; 
secondArray = [[NSMutableArray alloc] initWithObjects: @"123", @"456",  nil]; 
thirdArray = [[NSMutableArray alloc] initWithObjects: @"78", @"90", nil]; 
} 



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
return [mainArray count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 

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


cell.textLabel.text = [mainArray objectAtIndex:[indexPath row]]; 

return cell; 
} 

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

table2 *table2Controller = [[table2 alloc] initWithNibName:@"table2" bundle:nil]; 
table2Controller.arrayForDisplay = [[mainArray objectAtIndex: [indexPath row]] objectAtIndex:1]; 
[self.navigationController pushViewController:table2Controller animated:YES]; 

} 

@end 

table2.h

#import <UIKit/UIKit.h> 
@interface table2 : UITableViewController 
@property (nonatomic, strong) NSArray *arrayForDisplay; 
@end 

table2.m

@implementation table3 
@synthesize arrayForDisplay; 

その後ArrayTableViewController.m

編集に使用したのと同じセル構成のスタイル:

私が実行したときに、必要な変更を行った後、行を選択すると、次の行にSIGABRTというエラーが表示されます。

int main(int argc, char *argv[]) 
{ 
@autoreleasepool { 
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([ArrayTableAppDelegate class])); 
} 
} 

あなたはお勧めですか? ARCを無効にして自分のリリースに電話する必要がありますか?私は2番目のtableViewに行くことができるように?

+0

あなたの場合行を選択した後にクラッシュすると、 'didSelectRowAtIndexPath:'メソッドでいくつかの間違いをしたことになります。できますか?そのコードを表示しますか? – Ilanchezhian

+0

didSelectRowAtIndexPath:メソッドは現在のコードに編集されました – Webby

+0

'didSelectRowAtIndexPath'のために私の編集2を見てください。 – Ilanchezhian

答えて

3

まず間違い:viewDidLoad方法で

、あなたはそれらの配列を割り当てられた前であっても要素としてsecondArraymainArraythirdArrayを作成しました。

第二の間違い:

方法cellForRowAtIndexPath:で:

チェックラインcell.textLabel.text = [mainArray objectAtIndex:[indexPath row]];

は実際にtextLabelは、NSStringの値を設定することを期待します。しかし、あなたは配列を設定しています。

編集:

cell.textLabel.text = [[mainArray objectAtIndex:[indexPath row]] objectAtIndex:0]; 

実際にこれは、配列の最初の値を設定します:

次のようtextLabelに値を設定します。しかしそれはあなたの要求に依存します。

編集2:

arrayForDisplayは、配列変数ですが、あなたは次のように

table2Controller.arrayForDisplay = [[mainArray objectAtIndex: [indexPath row]] objectAtIndex:1]; 

はそれを行う文でそれに文字列変数を設定している:

table2Controller.arrayForDisplay = [mainArray objectAtIndex: [indexPath row]]; 
+0

あなたを助けますか? – Ilanchezhian

+0

はい、セル構成を除いて行います。配列の項目を表示するようにtableCellを設定するにはどうすればよいですか? – Webby

+0

私は自分の答えを更新しました。 Pl。それを確認します。 – Ilanchezhian