我是Xcode和Objective-C編程的新手,需要一些幫助。xcode陣列和UITableViews陣列
我期待爲使用分層數據和2個獨立的UITableViews
的iOS創建基本程序。我希望第二個UITableView
由在viewControllers
之間傳遞的數組填充,基於在第一個UITableView
中選擇哪個單元格/行。
程序編譯但運行程序時出現SIGABRT
錯誤。有人可以幫我修復SIGABRT
並將mainArray
傳遞給第二個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
並致電我自己的版本?這樣我可以得到第二個tableView
?
如果您在選擇一行後出現崩潰,那麼這意味着你在'didSelectRowAtIndexPath:'方法中犯了一些錯誤。你可以嗎?顯示代碼? – Ilanchezhian 2012-03-22 03:25:55
didSelectRowAtIndexPath:方法已編輯爲當前代碼 – Webby 2012-03-22 17:31:41
請參閱我的Edit 2 for'didSelectRowAtIndexPath'。 – Ilanchezhian 2012-03-23 05:55:39