2012-04-26 9 views
0

の機能を変更します。チケット数が0の場合、「 - 」は無効になり、チケット数が4の場合は「+」が無効になります。これまではうまくいっています。問題は、今度は、4行目の "+"ボタンをクリックするとテーブルのフレームサイズを変更し、4行目の " - "をクリックするとフレームサイズを取り戻したいのです。私はそうすると、「 - 」は、他の列の機能がrandomly.PLeaseは私が私がここwrong.Thanksをやって何を知っているように変更+ボタンの私のコードです変更するサイズは、チケットの数を増加し、私はこの「+」記号で</p> <p><img src="https://i.stack.imgur.com/xMRrL.png" alt="enter image description here"></p> <p>のようなカスタムセルを作成したカスタムセル

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *[email protected]"CellIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier]; 

    if (cell == nil) 
    { 
     cell 

= [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: CellIdentifier] autorelease]; 

      UILabel *labelOne = [[UI 

Label alloc]initWithFrame:CGRectMake(70, 10, 100, 20)]; 
      labelOne.tag = 100; 
      labelOne.backgroundColor=[UIColor clearColor]; 
      labelOne.font=[UIFont systemFontOfSize:14]; 
      [cell.contentView addSubview:labelOne]; 
      [labelOne release]; 

      minusbutton=[[UIButton alloc]initWithFrame:CGRectMake(152, 5, 15, 20)]; 
      minusbutton.tag=104; 
      [minusbutton setEnabled:NO]; 
      minusbutton.backgroundColor=[UIColor clearColor]; 
      [minusbutton addTarget:self action:@selector(DecreaseTickets:) forControlEvents:UIControlEventTouchUpInside]; 
      [minusbutton setTitle:@"-" forState:UIControlStateNormal]; 
      [minusbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
      [minusbutton setBackgroundImage:[UIImage imageNamed:@"button-green1.png"] forState:UIControlStateNormal]; 
      [cell.contentView addSubview:minusbutton]; 
      [minusbutton release]; 


      UILabel *quantity = [[UILabel alloc]initWithFrame:CGRectMake(170, 5, 20, 20)]; 
      quantity.tag = 103; 
      quantity.backgroundColor=[UIColor clearColor]; 
      quantity.font=[UIFont systemFontOfSize:12]; 
      [cell.contentView addSubview:quantity]; 
      [quantity release]; 

      addbutton=[[UIButton alloc]initWithFrame:CGRectMake(192, 5, 15, 20)]; 
      addbutton.tag=105; 
      addbutton.backgroundColor=[UIColor clearColor]; 
      [addbutton addTarget:self action:@selector(IncreaseTickets:) forControlEvents:UIControlEventTouchUpInside]; 
      [addbutton setTitle:@"+" forState:UIControlStateNormal]; 
      [addbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
      [addbutton setBackgroundImage:[UIImage imageNamed:@"button-green1.png"] forState:UIControlStateNormal]; 
      [cell.contentView addSubview:addbutton]; 
      [addbutton release]; 


      UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(240, 10, 80, 20)]; 
      labelTwo.tag = 101; 
      labelTwo.backgroundColor=[UIColor clearColor]; 
      labelTwo.font=[UIFont systemFontOfSize:14]; 
      labelTwo.textColor=[UIColor colorWithRed:0.25098 green:0.447059 blue:0.07451 alpha:1]; 
      [cell.contentView addSubview:labelTwo]; 
      [labelTwo release]; 


      UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(70, 30, 230, 30)]; 
      label3.tag = 102; 
      label3.backgroundColor=[UIColor clearColor]; 
      label3.numberOfLines=2; 
      label3.font=[UIFont systemFontOfSize:12]; 
      [cell.contentView addSubview:label3]; 
      [label3 release]; 



     } 
    } 


     UILabel *labelOne = (UILabel *) [cell.contentView viewWithTag:100]; 
     NSString *ss2=[[NSString alloc]initWithFormat:@"%@",[[eventTicketListArray objectAtIndex:indexPath.row ]tit] ]; 


     labelOne.text = ss2;  



     UILabel *labelTwo = (UILabel *) [cell.contentView viewWithTag:101]; 
     NSString *string2=[[NSString alloc]initWithFormat:@"%@",[[eventTicketListArray objectAtIndex:indexPath.row ]price] ]; 

      labelTwo.text =string2; 




     UILabel *label3 = (UILabel *) [cell.contentView viewWithTag:102]; 
     label3.text=[[NSString alloc]initWithFormat:@"%@",[[eventTicketListArray objectAtIndex:indexPath.row ]desc ] ]; 


     UILabel *label4 = (UILabel *) [cell.contentView viewWithTag:103]; 
     label4.text=[[NSString alloc]initWithFormat:@"%d",[[eventTicketListArray objectAtIndex:indexPath.row ]qty ] ]; 


    } 



    return cell; 


    } 

方法について

-(void)IncreaseTickets:(id)sender{ 
    NSIndexPath *indexPath =[ticketTable indexPathForCell:(UITableViewCell *)[[sender superview] superview]]; 
    NSUInteger row = indexPath.row; 




    UITableViewCell *currentCell = (UITableViewCell *)[[sender superview] superview] ; 

    for(UILabel *lbl in [currentCell.contentView subviews]) 
    { 
     if(([lbl isKindOfClass:[UILabel class]]) && ([lbl tag] == 103)) 
     { 
       str = [lbl.text intValue]; 

       str++; 

       eventTicketList=(EventDetailTicketsList *)[eventTicketListArray objectAtIndex:row]; 
       eventTicketList.qty=str; 

       lbl.text=[NSString stringWithFormat:@"%d",str]; 


     } 
    } 

     for(UIButton *btn in [currentCell.contentView subviews]) 
     { 
      if(([btn isKindOfClass:[UIButton class]]) && ([btn tag] == 105)) 
      { 


       if (str==4) { 
        [btn setEnabled:NO]; 
       } 
      } 


     } 

    for(UIButton *btn in [currentCell.contentView subviews]) 
    { 
    if(([btn isKindOfClass:[UIButton class]]) && ([btn tag] == 104)) 
    { 

      [btn setEnabled:YES]; 




    } 
    } 
    if (row==3) { 
     ticketTable.frame=CGRectMake(0, 0, 320, 70); 


    } 




    [currentCell setNeedsDisplay]; 



} 

方法をクリックしてください - ボタンクリック

-(void)DecreaseTickets:(id)sender{ 

    NSIndexPath *indexPath =[ticketTable indexPathForCell:(UITableViewCell *)[[sender superview] superview]]; 
    NSUInteger row = indexPath.row; 


    UITableViewCell *currentCell = (UITableViewCell *)[[sender superview] superview] ; 

    for(UILabel *lbl in [currentCell.contentView subviews]) 
    { 
     if(([lbl isKindOfClass:[UILabel class]]) && ([lbl tag] == 103)) 
     { 

      str = [lbl.text intValue]; 

      str--; 

      eventTicketList=(EventDetailTicketsList *)[eventTicketListArray objectAtIndex:row]; 
      eventTicketList.qty=str; 


      lbl.text=[NSString stringWithFormat:@"%d",str]; 
     } 
    } 

    for(UIButton *btn in [currentCell.contentView subviews]) 
    { 
     if(([btn isKindOfClass:[UIButton class]]) && ([btn tag] == 104)) 
     { 

      if (str<=0) { 
       [btn setEnabled:NO]; 




      } 
     } 

    } 
    for(UIButton *btn in [currentCell.contentView subviews]) 
    { 
     if(([btn isKindOfClass:[UIButton class]]) && ([btn tag] == 105)) 
     { 
      [btn setEnabled:YES]; 
     } 

    } 
     if (row==3){ 
     ticketTable.frame=CGRectMake(0, 0, 320, 200); 
    } 

    [currentCell setNeedsDisplay]; 



} 
+0

そのないカスタムセル – Narayana

+0

を使用するための良い方法は、あなたが私にはカスタムセルに良い方法が説明されているリンクを参照してくださいだろう...お手伝いを致します。ありがとう。 – NoviceDeveloper

+0

これを試してみてください(http://iphone.galloway.me.uk/iphone-sdktutorials/custom-uitableviewcell/)またはこの[one](http://www.iphonesdkarticles.com/2009/02/uitableview-サブビューをセルに追加する.html) –

答えて

0

ボタンをクリックしてコードを追加するか、didSelectRowForIndexPathでこのメソッドを使用することもできます。

[self.tableView beginUpdates]; 
[self.tableView endUpdates]; 

これを使用すると、自動的にテーブルビュー呼び出し以下のメソッドが処理されます。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 300;// here you can calculate cell height according to your requirements. 
} 

希望、これは

関連する問題

 関連する問題