2011-05-30 55 views
3

我有點強迫症,這讓我瘋狂。很長一段時間我一直在搞這些設置。刪除我分組的UITableView中的頂部陰影?

我有一個UITableView分組,我有一個陰影在上面。當您點擊頂部單元格時,它將被刪除。是什麼賦予了?

在過去的一個小時左右,我一直強調這一點。有沒有簡單的解決方案呢?或者我只是瘋了?

感謝, 庫爾頓

enter image description here

編輯:

viewDidLoad中:

formTableView.backgroundColor = [UIColor clearColor]; 
formTableView.layer.borderColor = [UIColor clearColor].CGColor; 
formTableView.separatorColor = [UIColor colorWithRed:(194.0/255.0) green:(194.0/255.0) blue:(194.0/255.0) alpha: 1]; 

這是我如何顯示我的細胞。 警告:這是很多代碼。在這裏有一堆東西需要進行分類,所以要自行承擔風險! :)

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 

} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
return 2; 
} 


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
return UITableViewCellEditingStyleNone; 
} 

// What to do when you click delete. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
return NO; 
} 

//RootViewController.m 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

if (section == 0) { 
    return [formDataOne count]; 
} else { 
    return [formDataTwo count]; 
} 
} 

//RootViewController.m 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 



static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
} 

for (UIView *subview in [cell.contentView subviews]) { 
    [subview removeFromSuperview]; 
} 

// Set up the cell... 
NSString *cellValue; 
if (indexPath.section == 0) { 
    cellValue = [formDataOne objectAtIndex:indexPath.row]; 
} else { 
    cellValue = [formDataTwo objectAtIndex:indexPath.row]; 
} 


if (indexPath.section == 0) { 
    cell.text = @""; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    if (indexPath.row == 0) { 
     addTitle = [[UITextField alloc] initWithFrame:CGRectMake(13, 13, 280, 20)]; 
     addTitle.borderStyle = UITextBorderStyleNone; 
     addTitle.textColor = [UIColor blackColor]; //text color 
     addTitle.font = [UIFont systemFontOfSize:16.0]; //font size 
     addTitle.placeholder = @"Album Name"; //place holder 
     addTitle.backgroundColor = [UIColor clearColor]; //background color 
     addTitle.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support 
     addTitle.keyboardType = UIKeyboardTypeDefault; // type of the keyboard 
     addTitle.returnKeyType = UIReturnKeyDone; // type of the return key 
     addTitle.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right 
     addTitle.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed 
     [cell.contentView addSubview:addTitle]; 
    } else if (indexPath.row == 1) { 
     // Set up loading text and show it 
     UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, 13, 280, 20)]; 
     myLabel.text = @"Private Album"; 
     myLabel.textColor = [UIColor blackColor]; 
     myLabel.textAlignment = UITextAlignmentLeft; 
     myLabel.backgroundColor = [UIColor clearColor]; 
     myLabel.font = [UIFont fontWithName:@"Helvetica" size: 16.0]; 
     myLabel.numberOfLines = 0; 
     //[myLabel sizeToFit]; 


     privateSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)]; 
     [privateSwitch addTarget:self action:@selector(switchToggled:) forControlEvents: UIControlEventTouchUpInside]; 
     [cell.contentView addSubview:privateSwitch]; 
     //[privateSwitch setOn:NO animated:NO]; 

     if ([howToDisplay isEqualToString:@"no"]) { 
      [privateSwitch setOn:NO animated:NO]; 
     } else { 
      [privateSwitch setOn:YES animated:NO]; 
     } 



     [cell.contentView addSubview:myLabel]; 
    } else { 
     // Set up loading text and show it 
     UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, 13, 280, 20)]; 
     myLabel.text = @"Comments"; 
     myLabel.textColor = [UIColor blackColor]; 
     myLabel.textAlignment = UITextAlignmentLeft; 
     myLabel.backgroundColor = [UIColor clearColor]; 
     myLabel.font = [UIFont fontWithName:@"Helvetica" size: 16.0]; 
     myLabel.numberOfLines = 0; 
     //[myLabel sizeToFit]; 
     [cell.contentView addSubview:myLabel]; 

     commentsSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)]; 
     [cell.contentView addSubview:commentsSwitch]; 
     [commentsSwitch setOn:YES animated:NO]; 
    } 

} else { 
    //cell.text = cellValue; 

    UILabel *labelOne = [[UILabel alloc] initWithFrame:CGRectMake(48, 12, 130, 20)]; 
    labelOne.text = cellValue; 
    labelOne.textColor = [UIColor blackColor]; 
    [labelOne setFont:[UIFont boldSystemFontOfSize:16]]; 
    labelOne.textAlignment = UITextAlignmentLeft; 
    labelOne.backgroundColor = [UIColor clearColor]; 
    //labelOne.font = [UIFont fontWithName:@"Helvetica"]; 
    labelOne.numberOfLines = 0; 
    [cell.contentView addSubview:labelOne]; 



    if (indexPath.row == 0) { 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } else if (indexPath.row == 1) { 
     int countFacebook = [dataCeter.connectionFacebookArray count]; 
     if (countFacebook == 0) { 
      cell.selectionStyle = UITableViewCellSelectionStyleBlue; 
     } else { 
      cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     } 
    } else if (indexPath.row == 2) { 

    //} else if (indexPath.row == 3) { 

    } else if (indexPath.row == 3) { 
     int countTumblr = [dataCeter.connectionTumblrArray count]; 
     if (countTumblr == 0) { 
      cell.selectionStyle = UITableViewCellSelectionStyleBlue; 
     } else { 
      cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     } 
    } else if (indexPath.row == 4) { 

    } else if (indexPath.row == 5) { 

    } else { 
     cell.selectionStyle = UITableViewCellSelectionStyleBlue; 
    } 

} 

// Set imageView with correct thumbnail 
UIImage *theImage; 
if ([cellValue isEqualToString:@"Facebook"]) { 

    theImage = [UIImage imageNamed:@"icon_small_facebook.png"]; 
    int countFacebook = [dataCeter.connectionFacebookArray count]; 
    NSLog(@"facebook? %d // %@", countFacebook, dataCeter.connectionFacebookArray); 

    if (countFacebook != 0) { 
     facebookSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)]; 
     [cell.contentView addSubview:facebookSwitch]; 
     [facebookSwitch setOn:YES animated:NO]; 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } else { 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

} else if ([cellValue isEqualToString:@"Twitter"]) { 

    theImage = [UIImage imageNamed:@"icon_small_twitter.png"]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

} else if ([cellValue isEqualToString:@"Flickr"]) { 

    theImage = [UIImage imageNamed:@"icon_small_flickr.png"]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

} else if ([cellValue isEqualToString:@"Tumblr"]) { 

    theImage = [UIImage imageNamed:@"icon_small_tumblr.png"]; 
    int countTumblr = [dataCeter.connectionTumblrArray count]; 

    if (countTumblr != 0) { 
     tumblrSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)]; 
     [cell.contentView addSubview:tumblrSwitch]; 
     [tumblrSwitch setOn:YES animated:NO]; 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } else { 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

} else if ([cellValue isEqualToString:@"Email"]) { 

    theImage = [UIImage imageNamed:@"icon_small_email.png"]; 
    int countEmail = [dataCeter.connectionEmailArray count]; 

} else if ([cellValue isEqualToString:@"MMS"]) { 

    theImage = [UIImage imageNamed:@"icon_small_mms.png"]; 
    int countMMS = [dataCeter.connectionSMSArray count]; 

} else if ([cellValue isEqualToString:@"Photostream"]) { 

    theImage = [UIImage imageNamed:@"icon_small_photostream.png"]; 
    cell.accessoryType = UITableViewCellAccessoryNone; 
    photostreamSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)]; 
    [cell.contentView addSubview:photostreamSwitch]; 
    [photostreamSwitch setOn:YES animated:NO]; 

} else { 

    theImage = nil; 
    cell.accessoryType = UITableViewCellAccessoryNone; 

} 
cell.imageView.image = theImage; 

    return cell; 
} 

回答

8

將表格視圖的分隔符樣式設置爲UITableViewCellSeparatorStyleSingleLine。它目前被設置爲UITableViewCellSeparatorStyleSingleLineEtched,它在iPhone上具有雙倍的上邊框效果(它在iOS 5上更加詳細,在iPad上的iOS 3.2和4上更加詳細)。

+0

啊哈,這似乎是正確的方向。尼斯。 – makdad 2011-05-30 01:47:43

+0

它是'UITableViewCellSeparatorStyleSingleLine':)...非常感謝!我的解決方案:'formTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;' – iosfreak 2011-05-30 02:08:42

+0

@ phpnerd211:糟糕,這是正確的:) – BoltClock 2011-05-30 02:38:07

1

你不是瘋了,它看起來像有一個額外的像素在那裏。

嘗試取出「分享」,看看它是否仍然發生。好奇看看陰影是在「分享」還是在桌子本身。

如果是這樣的話,那麼你知道你的標題視圖有問題,而不是表視圖。

+0

刪除它,它仍然存在。 – iosfreak 2011-05-30 01:22:33

+0

我可以看到生成單元格並設置高度的表格代碼嗎? – makdad 2011-05-30 01:32:16

+0

請檢查我的更新。 – iosfreak 2011-05-30 01:39:55