2010-10-08 5 views
1

Le problème avec cette application est que le TapCatchingController ne reçoit pas les robinets qui sont sur les en-têtes de section ou entre les sections. J'aimerais apprendre comment je devrais faire ça. J'ai essayé de garder mon programme d'exemple aussi petit que possible, mais il est encore assez long, désolé pour cela. Le code est cependant autonome. Si vous copiez et collez-le dans votre AppDelegate , vous devriez être prêt à partir! :)Je dois tout attraper! - UIView sur UITableView ne recevant pas de taps

Merci à l'avance, --Nick

#import <UIKit/UIKit.h> 

//----------------------------------------------------------------------------------------------- 
//Class InfiniteViewController: Says something when view is tapped, view is invisible to the user 
@interface TapCatchingViewController : UIViewController {} @end 
@implementation TapCatchingViewController 
- (void) loadView { 
    self.view = [[UIView alloc] init]; 
    self.view.alpha = 1.0; 
} 

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"You tapped this! Tuhm-dudu-dum"); } 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } 
- (void) viewWillDisappear:(BOOL)animated { [super viewWillDisappear: animated]; } 
@end 

//----------------------------------------------------------------------------------------------- 
//Class SuperViewControoler: A tableview who has on top of it an InfiniteViewController's view 
//Any tap on a SuperViewController's view should pass through the InfiniteViewController 
@interface SuperViewController : UITableViewController { 
    TapCatchingViewController * vc; 
} 
@end 

static const int sections = 7; 
static const int rowsPerSection = 9; 

@implementation SuperViewController 
- (void) viewDidLoad { 
    vc = [[TapCatchingViewController alloc] init]; 
    vc.view.frame = CGRectInfinite; 
    [self.view addSubview: vc.view]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return sections; } 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return rowsPerSection; } 
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return @"Section Header"; } 
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 250.0f; } 

- (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] autorelease]; 
    cell.textLabel.text = @"Meow, meow."; 
    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {} 

- (void)dealloc { 
    [vc dealloc]; 
    [super dealloc]; 
} 
@end 

//----------------------------------------------------------------------------------------------- 
//Class AppDelegate! The usual stuff :) 
@interface InfiniviewsAppDelegate : NSObject <UIApplicationDelegate> { 
    UIWindow *window; 
    UIViewController * vc; 
} 
@property (nonatomic, retain) IBOutlet UIWindow *window; 
@end 

@implementation InfiniviewsAppDelegate 
@synthesize window; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    vc = [[SuperViewController alloc] initWithStyle: UITableViewStyleGrouped]; 
    [window addSubview: vc.view]; 
    [window makeKeyAndVisible]; 
    return YES; 
} 

- (void)applicationWillResignActive:(UIApplication *)application {} 
- (void)applicationDidBecomeActive:(UIApplication *)application {} 
- (void)applicationWillTerminate:(UIApplication *)application {} 
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {} 
- (void)dealloc { 
    [vc release]; 
    [window release]; 
    [super dealloc]; 
} 
@end 

Répondre

0

Je ne suis pas sûr que je comprends votre problème ou non, mais seul problème que je vois est le point de vue de viewController est ajouté avec [self.view addSubview: vc.view]; mais il y a aucune garantie que ce sera toujours au-dessus de la fenêtre

ligne de code peut manquer est [self.view bringSubviewToFront:vc.view];

Cependant, vous pouvez vérifier que vc.view est au-dessus ou bot par en appliquant différentes couleurs à vc.view

Cependant, je ne suis pas en mesure de comprendre votre objectif pourquoi vous ajoutez le point de vue du contrôleur de vue en TableViewController sous-classe

L'espoir, il est utile de vous