Iphone 在单元格内选择自定义UITextView时选择单元格

Iphone 在单元格内选择自定义UITextView时选择单元格,iphone,objective-c,Iphone,Objective C,我创建了一个自定义单元格函数,其中有两个UITextField,因为我不喜欢cell.textLabel和cell.detailTextLabel的外观。在CellForRowatineXpath中为表创建单元格时,将调用此函数。当用户选择单元格时,会弹出一个键盘,允许您编辑第一个文本字段。但是,当您触摸第一个文本字段的文本或其附近时,它会拉起键盘,但不会触发textFieldShouldReturn函数,如果在其他地方选择单元格,该函数会触发。我有textFieldShouldReturn功能

我创建了一个自定义单元格函数,其中有两个UITextField,因为我不喜欢cell.textLabel和cell.detailTextLabel的外观。在CellForRowatineXpath中为表创建单元格时,将调用此函数。当用户选择单元格时,会弹出一个键盘,允许您编辑第一个文本字段。但是,当您触摸第一个文本字段的文本或其附近时,它会拉起键盘,但不会触发textFieldShouldReturn函数,如果在其他地方选择单元格,该函数会触发。我有textFieldShouldReturn功能将数据保存到应用程序

这是自定义单元格函数

{ CGRect CellFrame=CGRectMake(0,0,300,60);
CGRect Label1Frame=CGRectMake(10,8,1,25);
CGRect Label2Frame=CGRectMake(10,34,100,13);
CGRect Image1Frame=CGRectMake(265,10,30,30);
CGRect Image2Frame=CGRectMake(230,10,30,30)

}

cellForRowAtIndexPath函数

}


我使用willSelectRowAtIndexPath触发应用程序的其余部分,正如我前面所说的,只要不选择标签tempValue,一切都会正常工作。有没有一种方法,如果用户按下tempValue标签,它会将firstresponder传递给手机,这样if就能正确启动我的应用程序的其余部分?

我找到了答案,在发布这个问题之前我应该看得更清楚。这是terra关于userinteractionenabled的答案。我所做的是在创建单元格时,将我的文本字段(在示例代码中标记为tempValue)的userinteractionenabled设置为NO,然后在willSelectRowForIndexPath中将userinteractionenabled切换为YES。这太容易了,我本应该知道得更清楚。

我找到了答案,在我发布这个问题之前,我本应该看得更清楚。这是terra关于userinteractionenabled的答案。我所做的是在创建单元格时,将我的文本字段(在示例代码中标记为tempValue)的userinteractionenabled设置为NO,然后在willSelectRowForIndexPath中将userinteractionenabled切换为YES。这太容易了,我应该知道得更清楚。

如果堆栈溢出上已经有答案,请将该信息转发给我。如果堆栈溢出上已经有答案,请将该信息转发给我。
- (UITableViewCell *)getCellContentView:(NSString *)cellIdentifier
UITextField *lblTemp;
UIButton *imgTemp;

UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];

//initialize label with tag 1
lblTemp = [[UITextField alloc] initWithFrame:Label1Frame];
lblTemp.tag = 1;
[cell.contentView addSubview:lblTemp];
[lblTemp sizeToFit];
[lblTemp release];

lblTemp = [[UITextField alloc] initWithFrame:Label2Frame];
lblTemp.tag = 2;
[cell.contentView addSubview:lblTemp];
[lblTemp release];

imgTemp = [[UIButton alloc] initWithFrame:Image1Frame];
imgTemp.tag = 3;
[cell.contentView addSubview:imgTemp];
[imgTemp release];

imgTemp = [[UIButton alloc] initWithFrame:Image2Frame];
imgTemp.tag = 4;
[cell.contentView addSubview:imgTemp];
[imgTemp release];


return cell;
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  
{
UITableViewCell *cell;  
UITextField *tempValue;  
UITextField *descript;  

UIButton *primaryBtn;

UIButton *secondaryBtn;

cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentity];

if ([valueFromServer isEqualToString:@"comments"]) 
{
    cell = [self cellIsView:cellIdentity];

    messageTextView = (UITextView *)[cell viewWithTag:5];
    messageTextView.returnKeyType = UIReturnKeyDone;
}
if (cell == nil)
{
    cell = [self getCellContentView:cellIdentity];
}

primaryBtn = (UIButton *)[cell viewWithTag:3];
secondaryBtn = (UIButton *)[cell viewWithTag:4];

tempValue = (UITextField *)[cell viewWithTag:1];
if ([valueFromServer isEqualToString:@""])
{
    tempValue.textColor = [UIColor grayColor];
}
tempValue.textColor = [UIColor blackColor];
tempValue.font = [UIFont boldSystemFontOfSize:16];
tempValue.placeholder = @"Touch cell to edit"; 
tempValue.text = getServerData;

descript = (UITextField *)[cell viewWithTag:2];
descript.enabled = NO;
descript.textColor = [UIColor darkGrayColor];
descript.font = [UIFont boldSystemFontOfSize:10];
descript.text = getServerLabel;

[tempValue sizeToFit];

... 

return cell;