Удалить верхнюю тень в моем сгруппированном UITableView? - PullRequest
3 голосов
/ 30 мая 2011

Я немного ОКР, и это сводит меня с ума.Я долго возился с этими настройками.

У меня сгруппирован 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;
}

Ответы [ 2 ]

8 голосов
/ 30 мая 2011

Установите стиль разделителя вашего табличного представления на UITableViewCellSeparatorStyleSingleLine.В настоящее время он установлен на UITableViewCellSeparatorStyleSingleLineEtched, что дает эффект двойной верхней границы на iPhone (это выглядит более подробно на iOS 5, а также на iOS 3.2 и 4 на iPad).

1 голос
/ 30 мая 2011

Вы не сошли с ума, похоже, там есть дополнительный пиксель.

Попробуйте убрать "Общий доступ" и посмотрите, все ли еще произойдет. Любопытно посмотреть, находится ли тень на «Общий доступ» или на самой таблице.

Если это так, то вы знаете, что проблема связана с представлением заголовка, а не с представлением таблицы.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...