我有一个像这样的表格视图控制器,当单击一行时,它的颜色将变成蓝色,但我不想它,因为我有一个文本字段和每行中的标签。我怎样才能阻止它变成这样的蓝色?我该如何设置iphone应用程序中的表格视图单元格属性
这是我的电池构造代码:
- (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;
}
检查编辑答案, – iProgrammer 2011-05-27 05:48:23