gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 20:46:10 27 4
gpt4 key购买 nike

我有一个这样的 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com