objective-c - 我如何在 iphone 应用程序中设置表格 View 单元格属性

标签 objective-c cocoa-touch ios uitableview

我有一个这样的 TableView Controller ,当单击一行时,它的颜色会变成蓝色,但我不希望它变成这样,因为我在每一行中都有一个文本字段和一个标签。我怎样才能阻止它变成这样的蓝色?

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 =@"";
                tfText[0].placeholder =@"<Student Name>";

                cell.primaryLabel.text =@"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 =@"<Student Age>";

                cell.primaryLabel.text =@"Student Age: ";


            } 
                break;

            case 2:
            {
                 cell.primaryLabel.text =@"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 =@"<DD/MM/YYYY>";

                cell.primaryLabel.text =@"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 =@"<Blood Group>";

                cell.primaryLabel.text =@"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 =@"<Address>";

                cell.primaryLabel.text =@"Address: ";
            }
                break;

            default:
                break;


        }

最佳答案

其实只有一行代码...

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

关于objective-c - 我如何在 iphone 应用程序中设置表格 View 单元格属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6148200/

相关文章:

ios - 后台远程可操作通知 Web 服务调用不起作用?

ios - 在 iOS 的 UItableview 中将行推到顶部

android - Flutter 应用程序无法在 iOS 平台上运行

ios - HTTP 缓存适用于 GET,但不适用于 HEAD(在 iOS 7.1 上永远不会为 HEAD 获得 304)

ios - 使用 CGRectIntersectsRect 更新我的游戏分数

ios - 如何将字符串值传递给我应用程序中的所有 ViewController

ios - 如何在内容滚动时使用自动布局动画调整 UITextView 的底部约束

ios - 在 UITableView 的编辑模式下移动标题

iphone - UITableView 附件上的图标可以替换吗?

ios - UISegmentedControl 作为 UINavigationBar 标题项在一些延迟后加载