ios将自定义属性添加到uitableviewcell按钮

时间:2016-03-11 09:55:31

标签: ios objective-c uitableview

我在单个视图中有2个表。具有自定义单元格的table_1table_2

customCell *cell = (customCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

有两个按钮编辑和删除。 并为editBtn添加了目标方法:

[cell.btnEdit addTarget:self action:@selector(editBtnClick:) forControlEvents:UIControlEventTouchUpInside];

当我点击编辑按钮时,我想知道它是哪个表格的单元格按钮。为此,我想给“tabName”等自定义属性编辑按钮。

有没有办法做到这一点?

2 个答案:

答案 0 :(得分:2)

尝试使用带有关联引用的类别。它更清晰,适用于UIButton的所有实例。

的UIButton + Property.h

#import <Foundation/Foundation.h>

@interface UIButton(Property)

@property (nonatomic, retain) NSObject *property;

@end

的UIButton + Property.m

#import "UIButton+Property.h"
#import <objc/runtime.h>

@implementation UIButton(Property)

static char UIB_PROPERTY_KEY;

@dynamic property;

-(void)setProperty:(NSObject *)property
{
    objc_setAssociatedObject(self, &UIB_PROPERTY_KEY, property,     
    OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

-(NSObject*)property
{
    return (NSObject*)objc_getAssociatedObject(self, &UIB_PROPERTY_KEY);
}

@end

/示例用法

#import "UIButton+Property.h"

...

UIButton *button1 = [UIButton     
buttonWithType:UIButtonTypeRoundedRect];
button1.property = @"HELLO";
NSLog(@"Property %@", button1.property);
button1.property = nil;
NSLog(@"Property %@", button1.property);

答案 1 :(得分:1)

尝试使用此代码,我认为这可以帮助您轻松实现。

<record id="view_hr_attendance_main_filter" model="ir.ui.view">
    <field name="name">Attendances</field>
    <field name="model">hr.attendance.main</field>
    <field name="arch" type="xml">
        <search string="Attendance">
            <filter name="status_payroll" string="Draft" domain="[('attendance_status','=','draft')]" help="Draft Status" select ="1"/>
            <filter name="status_payroll_02" string="Approved" domain="[('attendance_status','=','approved')]" help="Draft Status" select ="1"/>
            <filter name="status_payroll_03" string="Post" domain="[('attendance_status','=','post')]" help="Draft Status" select ="1"/>
            <field name="name"/>
            <field name="assign_projects"/>
            <field name="month_of"/>
            <field name="month_quarter"/>
        </search>
    </field>
</record>

<record id="open_module_hr_attendance_main" model="ir.actions.act_window">
    <field name="name">Attendances</field>
    <field name="res_model">hr.attendance.main</field>
    <field name="view_type">form</field>
    <field name="search_view_id" ref="view_hr_attendance_main_filter"/>
    <field name="context">{"search_default_status_payroll":1}</field>
    <field name="help" type="html">
        <p class="oe_view_nocontent_create">
            Click to Create an Attendance.
        </p>
    </field>
</record>