-1

我是一个新的 iPhone 程序员。我正在制作一个基于导航的应用程序。其中一个视图包含一个表格视图。我成功地制作了一个单视图应用程序,该应用程序在视图内使用带有开关的表视图,但是当我在基于导航的应用程序中尝试代码时,它崩溃了:线程 1:程序收到信号:“SIGABRT”。

这是我的代码:FourthViewController.h

#import <UIKit/UIKit.h>
@interface FourthViewController : UIViewController {
NSArray *contentArray;
}

@property (strong, nonatomic) IBOutlet UITableView *table;
- (void) switchChanged;
@end

第四视图控制器.m

@implementation FourthViewController
@synthesize table;

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidLoad
{
contentArray = [NSArray arrayWithObjects:
                @"One",
                @"Two",
                @"Three", nil];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
[self setTable:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

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

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

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

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
    return YES;
}
}
//Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section     {
//return 0;
return [contentArray 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] ;
    UISwitch *switchview = [[UISwitch alloc] initWithFrame:CGRectZero];

    [switchview setOn:YES animated:NO];
    NSInteger row;
    row = [indexPath row];
    switchview.tag = row;
    [switchview addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
    cell.accessoryView = switchview;
}
cell.textLabel.text = [contentArray objectAtIndex:indexPath.row];
return cell;
}
- (void) switchChanged:(id)sender{
UISwitch *switchview = sender;
if (switchview.tag == 0) {
    NSLog(@"First");
}

}
@end

FourthViewController.xib 包含: TableView 连接到表属性数据源和委托设置为文件的所有者。

我做错了什么?

4

2 回答 2

1

我认为您需要在文件所有者中连接您的 IBOutlet 表。

或者

请更改如下。

#import <UIKit/UIKit.h>
@interface FourthViewController : UITableViewController <UITableViewDataSource,UITableViewDelegate>
{
NSArray *contentArray;
}

@property (strong, nonatomic) IBOutlet UITableView *table;
- (void) switchChanged;
@end
于 2012-04-29T17:07:05.540 回答
0

该错误与表格视图无关

于 2012-06-05T14:06:03.340 回答