Вы должны сделать заказ ячейки так:
CustomCell.h
@protocol CustomCellDelegate <NSObject>
- (void)buttonPressed:(UIButton *)sender;
@end
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell
@property (weak, nonatomic) id<CustomCellDelegate> delegate;
@property (weak, nonatomic) IBOutlet UIButton *button;
- (IBAction)buttonPressed:(UIButton *)sender;
@end
CustomCell.m
#import "CustomCell.h"
@implementation CustomCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)prepareForReuse{
self.button.enable = YES;
}
- (IBAction)buttonPressed:(UIButton *)sender{
[self.delegate buttonPressed:sender];
}
@end
после IB в добавлении нового UITableViewCell в вашем UITableView и его классе с новой пользовательской ячейкой задайте идентификатор идентификатора, например «Cust omCell»добавить кнопку для пользовательской ячейке и подключить к розетке, то изменить вам Tableview: cellForRowAtIndexPath: как это:
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"CustomCell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.delegate = self;
return cell;
}
- (void)buttonPressed:(UIButton *)sender{
sender.enable = NO;
}
Также вы должны добавить CustomCellDelegate в подогревателя файле вашего контроллера
Что значит «состояние»? –
Я хочу отключить кнопку, когда я нажимаю. Но проблема в том, что ячейка используется повторно, поэтому, когда я просматриваю представление таблицы, кнопка из другой ячейки также не сможет щелкнуть. – babygau
у вас есть пользовательская ячейка? –