0

2つの同じtableViewがあり、両方とも同じコード、同じコンテンツ、同じデザインであるため、私のコードは間違いではないと確信しています。しかし、私のtableViewの1つが表示され、もう1つが表示されない理由がわかりません。動的プロトタイプコンテンツ、グループ化されたスタイルを使用しており、両方のtableViewが他のViewControllerのコンテナビューにあります。コードは次のとおりです。

table.h

#import <UIKit/UIKit.h>

@interface table : UIViewController <UITableViewDataSource, UITableViewDelegate>

{
    NSArray *tabledata;
    NSIndexPath* checkedIndexPath;
}
@property (nonatomic, retain) NSArray *tabledata;
@property (nonatomic, assign) int number;
@property (nonatomic, retain) NSIndexPath* checkedIndexPath;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
+(table*)instance;
@property (nonatomic) NSInteger selectedRow;

@end

table.m

#import "table.h"

@interface table ()

@end

@implementation table
@synthesize tabledata;
@synthesize tableView;
@synthesize checkedIndexPath;
@synthesize number;
+(InstrumentsI*)instance {
    static table *statInst;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        statInst = [[table alloc] init];
    });
    return statInst;
}
@synthesize selectedRow;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    tabledata = [[NSArray alloc] initWithObjects:@"row1", @"row2", @"row3", nil];
    self.selectedRow = 0;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark - TableView Data Source methods

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

- (UITableViewCell *)tableView:(UITableView *)tableview cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    cell = [tableview dequeueReusableCellWithIdentifier:@"identifer"];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"identifer"];
    }

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

    if (indexPath.row == self.selectedRow)
    {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}

#pragma mark TableView Delegate methods

- (void)tableView:(UITableView *)tableview didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [table instance].selectedRow = indexPath.row;
    if (indexPath.row != self.selectedRow) {
        self.selectedRow = indexPath.row;
    }
    [tableView reloadData];
}


- (void)viewDidUnload {
    [self setTableView:nil];
    [super viewDidUnload];
}
@end
4

2 に答える 2

1

すべてのデリゲートとデータソース メソッドを実装したかどうかを確認してください。

また、ファイルの所有者またはコントローラーをデリゲートおよびデータソースとして設定したことを確認してください。

于 2012-12-29T14:09:49.667 に答える
0

次のように、データをロードした後にテーブルビューをリロードしてみてください。

- (void)viewDidLoad
{
    [super viewDidLoad];
    tabledata = [[NSArray alloc] initWithObjects:@"row1", @"row2", @"row3", nil];
    self.selectedRow = 0;
    [self.tableView reloadData];
}
于 2012-12-29T13:56:35.420 に答える