사용자 지정 UITableViewCell 하위 클래스가 필요합니다. 뭐 그런 :
.H 파일 :
#define kBackButtonPressedNotification @"kBackButtonPressedNotification"
#define kForwardButtonPressedNotification @"kForwardButtonPressedNotification"
@interface ButtonsTableViewCell : UITableViewCell {
@private
UIButton* _backButton;
UIButton* _forwardButton;
}
@end
하는 .m 파일 :
@implementation ButtonsTableViewCell
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if(self){
_backButton = [UIButton buttonWithType:UIButtonTypeCustom];
_backButton.frame = CGRectMake(10, 10, 100, 30); //put numbers that are good for you
[_backButton setImage:[UIImage imageNamed:@"someBackButtonImage.png"] forState:UIControlStateNormal];
[_backButton addTarget:self action:@selector(backPressed) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:_backButton];
_forwardButton = [UIButton buttonWithType:UIButtonTypeCustom];
_forwardButton.frame = CGRectMake(10, 10, 100, 30); //put numbers that are good for you
[_forwardButton setImage:[UIImage imageNamed:@"someForwardButtonImage.png"] forState:UIControlStateNormal];
[_forwardButton addTarget:self action:@selector(forwardPressed) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:_forwardButton];
}
return self;
}
-(void)backPressed{
[[NSNotificationCenter defaultCenter]postNotificationName:kBackButtonPressedNotification object:nil];
}
-(void)forwardPressed{
[[NSNotificationCenter defaultCenter]postNotificationName:kForwardButtonPressedNotification object:nil];
}
@end
행 + 1의 컨트롤러의 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
방법 반환 번호에 (추가 행 버튼). -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
에서 indexPath.row를 확인하고 마지막 사용자 인 경우 해당 맞춤 셀의 인스턴스를 반환합니다.
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(yourBackMethod) name:kBackButtonPressedNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(yourForwardMethod) name:kForwardButtonPressedNotification object:nil];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
이
yourBackMethod
및
yourForwardMethod
에 대한 적절한 구현을 제공하는 것을 잊지 마세요 : 그리고 물론 당신의이 같은 말을하자, 그 알림을 등록해야합니다.
어디서 버튼을 원하십니까? 10 행이 표시된 후 – Ariel
이 표시됩니다. – Illep
그런 다음 그 버튼이있는 행을 하나 더 추가하면됩니다 ... – Ariel