2012-03-26 6 views
2

と呼ばれていない - しかし、デリゲートは、受信ビューに呼び出されていない - 私はすべてのコードを投稿します:UITableViewDelegateが

リストヘッダファイル:

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

@class iTanksV2ListViewController; 
@protocol iTanksV2ListViewControllerDelegate 
    - (void) iTanksListViewController:(iTanksV2ListViewController *) sender choseTank:(tank *)tank; 
@end 

@interface iTanksV2ListViewController : UITableViewController 
@property (nonatomic, strong) NSArray *tanks; 
@property (weak, nonatomic) IBOutlet UITableView *tankTableView; 
@property (weak, nonatomic) id <iTanksV2ListViewControllerDelegate> delegate; 
@end 

およびmファイル:

#import "iTanksV2ListViewController.h" 
#import "tank.h" 
#import "tankDetailViewController.h" 

@interface iTanksV2ListViewController() 

@end 

@implementation iTanksV2ListViewController 
@synthesize tanks = _tanks; 
@synthesize tankTableView = _tankTableView; 
@synthesize delegate = _delegate; 


- (id)initWithStyle:(UITableViewStyle)style 
{ 
    self = [super initWithStyle:style]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // Uncomment the following line to preserve selection between presentations. 
    // self.clearsSelectionOnViewWillAppear = NO; 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    // self.navigationItem.rightBarButtonItem = self.editButtonItem; 
} 

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

#pragma mark - Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    // Return the number of sections. 
    return 1;//keep this section in case we do need to add sections in the future. 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return [self.tanks count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Tank List Table Cell"; 
    UITableViewCell *cell = [self.tankTableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (!cell) 
    { 
     cell = [[UITableViewCell alloc] initWithFrame:CGRectZero]; 
    } 
    tank *thisTank = [self.tanks objectAtIndex:indexPath.row]; 
    cell.textLabel.text = thisTank.tankNumber; 
    return cell; 
} 

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if([segue.identifier isEqualToString:@"Show Tank Details"]) 
    { 

    } 
} 

#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    tank *thisTank = [self.tanks objectAtIndex:indexPath.row]; 
    [self.delegate iTanksListViewController:self choseTank:thisTank]; 

} 

@end 

、受信ファイルのヘッダ:

#import <UIKit/UIKit.h> 
#import "tankGauge.h" 
#import "tank.h" 

@interface tankDetailViewController : UIViewController 
@property (weak, nonatomic) IBOutlet UILabel *tankNumberLabel; 
@property (weak, nonatomic) IBOutlet UILabel *tankProductLabel; 
@property (weak, nonatomic) IBOutlet UILabel *tankAvailableProductLabel; 
@property (weak, nonatomic) IBOutlet UILabel *tankMaxVolumeLabel; 
@property (weak, nonatomic) IBOutlet tankGauge *tankVolumeGauge; 
@property (weak, nonatomic) tank* tankToShow; 
@end 

...と、m個のファイル:

#import "tankDetailViewController.h" 
#import "iTanksV2ListViewController.h" 

@interface tankDetailViewController() <iTanksV2ListViewControllerDelegate> 

@end 

@implementation tankDetailViewController 
@synthesize tankNumberLabel = _tankNumberLabel; 
@synthesize tankProductLabel = _tankProductLabel; 
@synthesize tankAvailableProductLabel = _tankAvailableProductLabel; 
@synthesize tankMaxVolumeLabel = _tankMaxVolumeLabel; 
@synthesize tankVolumeGauge = _tankVolumeGauge; 
@synthesize tankToShow = _tankToShow; 


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

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

-(void)iTanksListViewController:(iTanksV2ListViewController *)sender choseTank:(id)tank 
{ 
    self.tankToShow = tank; 
    self.tankNumberLabel.text = self.tankToShow.tankNumber; 
} 

- (void)viewDidUnload 
{ 
    [self setTankNumberLabel:nil]; 
    [self setTankProductLabel:nil]; 
    [self setTankAvailableProductLabel:nil]; 
    [self setTankMaxVolumeLabel:nil]; 
    [self setTankVolumeGauge:nil]; 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

@end 

答えて

3

tankTableViewIBOutletあるので、以下に示すように、あなたは自分のxibであなたのFile's OwnerにあなたのtableViewのデリゲートとデータ・ソースを接続する必要があります。 はenter image description here

+0

私はちょうどチェックしたと私はこれが行われたと思う - デリゲートとデータソースは両方itanksv2listviewcontrollerに設定されています:-Sは正しいですか? – HillInHarwich

+0

絶対に!あなたはそれらをプログラム的にあるいは 'xib'を通して設定していますか? – tipycalFlow

+0

彼らは私が思うストーリーボードを通して設定されています!私はこれに新しいですし、それは現時点では複雑なようです! :-S – HillInHarwich

0

は、あなたがそのテーブルビューのためのデリゲートとしてそれのViewControllerを設定することがありますか?

+0

は、私はそう思います!ビューコントローラの実装では、ビュー内の最後のコード... – HillInHarwich

関連する問題