0

UITableView コントロールを備えた単純なテーブル ビュー コントローラーがあります。ヘッダー ファイルに UITableViewDelegate と UITableViewDatasource を実装しました。データ ソースとデリゲートを、UITableView を含む ViewController に割り当てました。ただし、どのテーブル ビュー メソッドも起動していません。ソース コードを削除したものと、デリゲート/データソースを示すスクリーン ショットを投稿しました。イベントが配線されない理由として考えられるのは何ですか?

(gauges は値オブジェクトの NSArray を含むモデルです)

ヘッダ

#import <UIKit/UIKit.h>
#import "GaugeList.h"

@interface SitePickerViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic,strong) GaugeList *gauges;

@end

実装

#import "SitePickerViewController.h"

@interface SitePickerViewController ()

@end

@implementation SitePickerViewController
@synthesize gauges;

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

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSInteger rowCount = [gauges.gaugeList count];
    NSLog(@"numberOfRowsInSection called: %i\n", rowCount);
    return rowCount;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"cellForRowAtIndexPath\n");
    UITableViewCell *cell = [[UITableViewCell alloc] init];
    return cell;
}

-(void)loadView{
    gauges = [[GaugeList alloc] initWithStateIdentifier:@"WV" andType:nil];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view.
    NSLog(@"viewDidLoad called: %i\n", [gauges.gaugeList count]);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
4

3 に答える 3

0

ビューでDidLoad

設定

tableView.delegate = self;

また、XIB を使用していない場合は、tableView も割り当てます。または、xib を使用してデリゲートとデータ ソースをファイル所有者にマップする場合

于 2013-03-21T13:16:35.637 に答える
0

SitePickerViewController をデリゲートおよびデータソースにするだけでは十分ではありません。また、そのクラスをデータソースおよびデリゲートとして設定する必要があります。そのIBOutletにも必ず接続してください。

@interface <UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *functionTableView;
@end

@implementation
- (void)viewDidLoad
{
    [super viewDidLoad];

    self.functionTableView.delegate = self;
    self.functionTableView.dataSource = self;
}

//Delegate and datasource methods down here
@end
于 2013-03-21T13:30:32.307 に答える
0

問題は、の実装にありloadViewます。の実装でloadViewは、コントローラのメイン ビューを実際に作成し、それを に割り当てる必要がありself.viewます。あなたが持っているように、ビューコントローラー用にビューが作成されることはありません。

必要なメソッド呼び出しを移動しますviewDidLoad

- (void)viewDidLoad {
    [super viewDidLoad];

    gauges = [[GaugeList alloc] initWithStateIdentifier:@"WV" andType:nil];

    // Do any additional setup after loading the view.
    NSLog(@"viewDidLoad called: %i\n", [gauges.gaugeList count]);
}
于 2013-03-21T22:03:33.677 に答える