UITapGestureRecognizer不适用于Xcode 4.1 / iOS 4.3

时间:2013-02-18 23:41:01

标签: ios4 uibutton uitableview uitapgesturerecognizer xcode4.1

我正在尝试使用此示例实现可扩展表视图单元格:
http://blog.paxcel.net/blog/expandablecollapsible-table-for-ios/
在这里,他们使用Xcode 4.3,iOS 5,但我必须使用Xcode4.1,iOS 4.3实现它。使用这个版本,我的视图/按钮无法识别按钮被点击的时间,但是我使用相同的类编译了我的项目,但使用Xcode 4.3 / iOS 5,并且点击它被识别,因此类很好。
以下是使用按钮创建UIView的代码:
SectionView.m

-(id)initWithFrame:(CGRect)frame withTitle:(NSString *)title section:(NSInteger)sectionNumber delegate:(id<SectionView>)Delegate{
    self = [super initWithFrame:frame];
    if(self){
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(discButtonPressed:)];
        [tapGesture setNumberOfTapsRequired:1];
        tapGesture.cancelsTouchesInView = NO;
        [self addGestureRecognizer:tapGesture];

        self.userInteractionEnabled = YES;

        self.section = sectionNumber;
        self.delegate = Delegate;

        CGRect labelFrame = self.bounds;
        labelFrame.size.width -= 50;
        CGRectInset(labelFrame, 0.0, 5.0);

        UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
        label.text = title;
        label.font = [UIFont boldSystemFontOfSize:16.0];
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor blackColor];
        label.textAlignment = UITextAlignmentLeft;
        [self addSubview:label];
        self.sectionTitle = label;

        CGRect buttonFrame = CGRectMake(labelFrame.size.width, 0, 50, labelFrame.size.height);
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = buttonFrame;
        [button addTarget:self action:@selector(discButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

        [self addSubview:button];
        self.discButton = button;
    }

    return self;
 }

这是从SectionView创建/委托的类:
TableDropViewController.h

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

@interface TableDropViewController : UITableViewController <SectionView>

@end

此方法创建对象SectionView:
TableDropViewController.m

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    SectionInfo *si = [self.sectionInfoArray objectAtIndex:section];
    if(!si.sectionView){
        NSString *title = si.category;
        si.sectionView = [[SectionView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 45) withTitle:title section:section delegate:self];
    }
    return si.sectionView;
}

我真的很感激帮助。感谢

0 个答案:

没有答案