Должен поймать все! - UIView поверх UITableView не получает нажатий - PullRequest
1 голос
/ 08 октября 2010

Проблема с этим приложением заключается в том, что TapCatchingController не получает ответвления, которые находятся на заголовках разделов или между разделами.Я хотел бы узнать, как я должен это сделать.Я старался сделать свою программу-образец как можно меньше, но она все еще довольно длинная, извините за это.Код, однако, самодостаточен.Если вы скопируете и вставите его в свой AppDelegate, вам будет хорошо!:)

Заранее спасибо, - Ник

#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

1 Ответ

0 голосов
/ 20 сентября 2017

Я не уверен, что понимаю вашу проблему или нет, но Единственная проблема, которую я вижу, это то, что представление viewController добавлено с [self.view addSubview: vc.view];, но нет никакой гарантии, что оно всегда будет поверх окна

Возможно, отсутствует строка кода [self.view bringSubviewToFront:vc.view];

Однако вы можете проверить, что vc.view находится на вершине или в боте, применив другой цвет к vc.view

.

Тем не менее я не могу понять вашу цель, почему вы добавляете представление контроллера представления в TableViewController подкласс

Надеюсь, это полезно для вас

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...