私は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
に行くことができるように?
あなたの場合行を選択した後にクラッシュすると、 'didSelectRowAtIndexPath:'メソッドでいくつかの間違いをしたことになります。できますか?そのコードを表示しますか? – Ilanchezhian
didSelectRowAtIndexPath:メソッドは現在のコードに編集されました – Webby
'didSelectRowAtIndexPath'のために私の編集2を見てください。 – Ilanchezhian