2011-05-27 41 views
0

我有一個像這樣的表格視圖控制器,當單擊一行時,它的顏色將變成藍色,但我不想它,因爲我有一個文本字段和每行中的標籤。我怎樣才能阻止它變成這樣的藍色?我該如何設置iphone應用程序中的表格視圖單元格屬性

screen shot of app

這是我的電池構造代碼:

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 


    CustomCellStudentData *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 

    // cell = [[[CustomCellStudentData alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    cell = [[[CustomCellStudentData alloc] initWithFrame:CGRectZero reuseIdentifier:nil] autorelease]; 
    } 


    switch(indexPath.section) 
    { 



     case 0: 
      switch (indexPath.row) 
     { 
      case 0: 
      { 

       tfText[0] = [[UITextField alloc] initWithFrame:CGRectMake(125,15, 170, 40)]; 
       cell.accessoryView = tfText[0]; 
       tfText[0].delegate=self; 
       tfText[0].text [email protected]""; 
       tfText[0].placeholder [email protected]"<Student Name>"; 

       cell.primaryLabel.text [email protected]"Student Name: "; 

      } 
       break; 
      case 1: 
      { 
       tfText[1] = [[UITextField alloc] initWithFrame:CGRectMake(125,15, 170, 40)]; 
       cell.accessoryView = tfText[1]; 
       tfText[1].delegate=self; 
       tfText[1].placeholder [email protected]"<Student Age>"; 

       cell.primaryLabel.text [email protected]"Student Age: "; 


      } 
       break; 

      case 2: 
      { 
       cell.primaryLabel.text [email protected]"Gender: "; 
       segmentedControl = [[UISegmentedControl alloc] initWithItems:nil]; 
       segmentedControl.segmentedControlStyle = UISegmentedControlStyleBezeled; 
       segmentedControl.frame = CGRectMake(100,10,200,30); 
       [segmentedControl insertSegmentWithTitle:@"Male" atIndex:0 animated:YES]; 
       [segmentedControl insertSegmentWithTitle:@"Female" atIndex:1 animated:YES]; 
       segmentedControl.selectedSegmentIndex = 1; 
       segmentedControl.tintColor = [UIColor purpleColor]; 
       segmentedControl.backgroundColor = [UIColor whiteColor]; 

       [segmentedControl setMomentary:YES]; 
       [segmentedControl addTarget:self action:@selector(segmentSwitch:) forControlEvents:UIControlEventValueChanged]; 
       cell.accessoryView =segmentedControl; 
       //[self.view addSubview:segmentedControl]; 

       /* 
       segmentedControl = [[UISegmentedControl alloc] initWithItems:nil]; 
       [segmentedControl insertSegmentWithTitle:@"Male" atIndex:0 animated:YES]; 
       [segmentedControl insertSegmentWithTitle:@"Female" atIndex:1 animated:YES]; 
       segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain; 
       segmentedControl.frame = CGRectMake(100,10,200,30); 
       [segmentedControl setMomentary:YES]; 
       [segmentedControl addTarget:self action:@selector(segmentSwitch:) forControlEvents:UIControlEventValueChanged]; 



       */ 
      } 
       break; 

      case 3: 
      { 
       tfText[3] = [[UITextField alloc] initWithFrame:CGRectMake(125,15, 170, 40)]; 
       cell.accessoryView = tfText[3]; 
       tfText[3].delegate=self; 
       tfText[3].placeholder [email protected]"<DD/MM/YYYY>"; 

       cell.primaryLabel.text [email protected]"Date Of Birth: "; 

      } 
       break; 
      case 4: 
      { 
       tfText[5] = [[UITextField alloc] initWithFrame:CGRectMake(125,15, 170, 40)]; 
       cell.accessoryView = tfText[5]; 
       tfText[5].delegate=self; 
       tfText[5].placeholder [email protected]"<Blood Group>"; 

       cell.primaryLabel.text [email protected]"Blood Group: "; 

      } 
       break; 

      case 5: 
      { 
       tfText[6] = [[UITextField alloc] initWithFrame:CGRectMake(125,15, 170, 40)]; 
       cell.accessoryView = tfText[6]; 
       tfText[6].delegate=self; 
       tfText[6].placeholder [email protected]"<Address>"; 

       cell.primaryLabel.text [email protected]"Address: "; 
      } 
       break; 

      default: 
       break; 


     } 
+0

檢查編輯答案, – iProgrammer 2011-05-27 05:48:23

回答

3

其實它只是一行代碼...

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
+0

哦是的!謝謝你 – Ravi 2011-05-27 05:45:08

0

內,您的方法,即添加的cellForRowAtIndexPath下面的代碼

UIView *bckv = [[UIView alloc] initWithFrame:CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width,cell.frame.size.height)]; 
bckv.backgroundColor = [UIColor colorWithRed:106/256.0 green:108.0/256.0 blue:107.0/256.0 alpha:0.0]; 
cell.selectedBackgroundView=bckv; 
[bckv release]; 


    OR 

cell.selectionStyle=UITableViewCellSelectionStyleNone; 

希望它可以幫助......

0
cell.selectionStyle = UITableViewCellSelectionStyleNone; 
相關問題