2013-09-06 2 views
-4

Я новичок в разработке IOS, у меня есть вид пользовательских таблиц, на которых размещены 3 кнопки, а именно,Как скрыть или показать кнопку выбора строки?

  1. Добавить комментарий
  2. стрелка вверх
  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]; 
} 

Это не работает, как ожидалось, что может быть проблема?

+6

кто достаточно храбр, чтобы прочитать эту книгу? –

+2

Будьте точны, укажите, в чем проблема, добавьте существенный код, поддерживающий ваш вопрос. –

+0

Я дал это для объяснения всей проблемы. спасибо –

ответ

-1

набор любое целое значение переменной в кнопки действия и поставить условие в heightForRowAtIndexPath, независимо от размера вы хотите, а затем перезагрузить стол

+0

скажите, если возникли проблемы – NullData

+0

Не хотите спрятать кнопку после клика. –

+0

UIButton * DownArrow declear это в .h и в вашем методе IncreseCellHight: write downArrow.hidden = yes; – NullData

Смежные вопросы