【问题标题】:Gotta Catch'm All! - UIView over UITableView not receiving taps必须抓住一切! - UITableView 上的 UIView 不接收点击
【发布时间】:2010-10-08 09:31:27
【问题描述】:

这个应用的问题是 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

【问题讨论】:

    标签: uitableview uiview ios


    【解决方案1】:

    我不确定我是否理解您的问题,但是 我能看到的唯一问题是 viewController 的视图添加了 [self.view addSubview: vc.view]; 但不能保证它总是在窗口的顶部

    可能缺少的代码行是[self.view bringSubviewToFront:vc.view];

    但是,您可以通过对 vc.view 应用不同的颜色来检查 vc.view 是否位于顶部或 bot 上

    我仍然无法理解您为什么要在 TableViewController 子类中添加视图控制器的视图

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      相关资源
      最近更新 更多