私は iOS 開発の初心者です。つまり、3 つのボタンを配置したカスタム テーブル ビューがあります。
- コメントを追加する
- 上矢印
- 下矢印
下矢印ボタンが押されたときにセルの高さを増やしたい、またコメント追加ボタン、下矢印ボタンを表示させたい。
私のコード、
#import "JCoutGoingConfess.h"
@interface JCoutGoingConfess (private)
- (BOOL)cellIsSelected:(NSIndexPath *)indexPath;
@end
@implementation JCoutGoingConfess
#define kCellHeight 132.0
@synthesize outConfessionNavbarBAckBtn,JCoutGoingTbl;
//---------------------------- TableView---------------------------------------
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animation
{
NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:1 inSection:0];
NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
// If our cell is selected, return double height
if([self cellIsSelected:indexPath]) {
return kCellHeight * 2.0;
}
return kCellHeight;
}
- (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];
}
// ----------------------- cellbackground image-----------------------------
if([self cellIsSelected:indexPath]){
cell.backgroundView =[[UIImageView alloc]initWithFrame:CGRectMake(160, 151, 320, 108)];
cell.backgroundView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"inCellFullBg.png"]];
}
// ******** imageView on cell *******
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(112,0, 90, 90)];
imgView.image = [UIImage imageNamed:@"friendsfacepic.png"];
[cell.contentView addSubview:imgView];
//----------------------------Cell buttons-------------------------------------------
if (JcOutCellSize==152)
{
UIButton *AddComment = [UIButton buttonWithType:UIButtonTypeCustom];
[AddComment addTarget:self
action:@selector(TestBtns:)
forControlEvents:UIControlEventTouchDown];
AddComment.frame = CGRectMake(9.0, 128.0, 96.0, 26.0);
[cell.contentView addSubview:AddComment];
UIImage *buttonAddComment = [UIImage imageNamed:@"addcomment.png"];
[AddComment setBackgroundImage:buttonAddComment forState:UIControlStateNormal];
[cell.contentView addSubview:AddComment];
UIButton *UpArrow = [UIButton buttonWithType:UIButtonTypeCustom];
[UpArrow addTarget:self
action:@selector(ResizeCell:)
forControlEvents:UIControlEventTouchDown];
//[DownArrow setTitle:@"Arrow" forState:UIControlStateNormal];
UpArrow.frame = CGRectMake(143.0, 136.0, 26.0, 16.0);
[cell.contentView addSubview:UpArrow];
UIImage *buttonUp = [UIImage imageNamed:@"upArrow.png"];
[UpArrow setBackgroundImage:buttonUp forState:UIControlStateNormal];
[cell.contentView addSubview:UpArrow];
}
//----------------------------------------------------------------------------------
if (JcOutCellSize==132)
{
NSLog(@" down arrow %f",JcOutCellSize);
UIButton *DownArrow = [UIButton buttonWithType:UIButtonTypeCustom];
[DownArrow addTarget:self
action:@selector(IncreseCellHight:)
forControlEvents:UIControlEventTouchDown];
DownArrow.frame = CGRectMake(143.0, 116.0, 26.0, 16.0);
[cell.contentView addSubview:DownArrow];
UIImage *buttondown = [UIImage imageNamed:@"upDownArrow.png"];
[DownArrow setBackgroundImage:buttondown forState:UIControlStateNormal];
[cell.contentView addSubview:DownArrow];
NSLog(@" cell size = %f",JcOutCellSize);
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:TRUE];
// Toggle 'selected' state
BOOL isSelected = ![self cellIsSelected:indexPath];
NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
[selectedIndexes setObject:selectedIndex forKey:indexPath];
[JCoutGoingTbl beginUpdates];
[JCoutGoingTbl endUpdates];
}
- (void)viewDidLoad
{
selectedIndexes = [[NSMutableDictionary alloc] init];
[super viewDidLoad];
}
- (void)viewDidUnload
{
selectedIndexes = nil;
[super viewDidUnload];
}
- (BOOL)cellIsSelected:(NSIndexPath *)indexPath {
// Return whether the cell at the specified index path is selected or not
NSNumber *selectedIndex = [selectedIndexes objectForKey:indexPath];
return selectedIndex == nil ? FALSE : [selectedIndex boolValue];
}
これは期待どおりに機能していません。何が問題なのですか?