Iphone 文本字段中的标记
我有三个单元格,其中每个单元格都有文本字段。现在我希望用户在哪个文本框中单击。这个方法textfielddidediting给了我用户正在输入的值,但是我没有得到textfield的任何标记 这是我的密码:Iphone 文本字段中的标记,iphone,xcode,sdk,Iphone,Xcode,Sdk,我有三个单元格,其中每个单元格都有文本字段。现在我希望用户在哪个文本框中单击。这个方法textfielddidediting给了我用户正在输入的值,但是我没有得到textfield的任何标记 这是我的密码: - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { switch (section) { case 0: return @"";
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{ switch (section)
{ case 0: return @"";
case 1: return @"";
default:return @"";
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if(optconscodecount != 0 && gotOK == 2)
return 2;
else
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch(section)
{ case 0: try=1; return conscodecount;
case 1: try=2; return optconscodecount;
default:return 0;}
}
// Heights per row
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{ int section = [indexPath section];
//int row = [indexPath row];
switch (section)
{case 0:return 80.0f;
case 1:return 80.0f;
default:return 80.0f;}
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"\n%@", appDelegate.conscodeNameArray);
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
row = [indexPath row];
section = [indexPath section];
switch (section)
{case 0:try=1;cell = [tableView dequeueReusableCellWithIdentifier:@"textCell"];
if (!cell)
{cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"textCell"] autorelease];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20.0f, 10.0f, 280.0f, 20.0f)];
[label setText:[appDelegate.conscodeNameArray objectAtIndex:row]];[cell addSubview:label]; [label release];
[cell addSubview:[[UITextField alloc] initWithFrame:CGRectMake(20.0f, 40.0f, 280.0f, 30.0f)]];
}
UITextField *tf = [[cell subviews] lastObject];
tf.placeholder = [appDelegate.conscodeNameArray objectAtIndex:row];
tf.tag =tagcount;
tagcount=tagcount+1;
tf.delegate = self;
tf.borderStyle = UITextBorderStyleRoundedRect;
return cell;
break;
case 1:
try=2;
cell = [tableView dequeueReusableCellWithIdentifier:@"textCell"];
if (!cell)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"textCell"] autorelease];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20.0f, 10.0f, 280.0f, 20.0f)];
[label setText:[appDelegate.optconscodeNameArray objectAtIndex:row]];
[cell addSubview:label];
[label release];
[cell addSubview:[[UITextField alloc] initWithFrame:CGRectMake(20.0f, 40.0f, 280.0f, 30.0f)]];
}
UITextField *my = [[cell subviews] lastObject];
my.tag = 0;
my.tag = my.tag+1;
my.placeholder = [appDelegate.optconscodeNameArray objectAtIndex:row];
my.delegate = self;
my.borderStyle = UITextBorderStyleRoundedRect;
return cell;
break;
return cell;
break;
default:
break;
}
return cell;
}
nameField.tag=1
agefield.tag = 2;
//在委托方法中,只需检查
if (textField.tag == 1) {
NSLog(@" clicked in Name field");
} else if (textField.tag ==2) {
NSLog(@" clicked in Age field");
}
如果要在实例变量中保留每个文本字段,可以在委托方法中进行简单比较,查看哪个字段已完成编辑。即使通过使用关联数组从实例映射到字段名,完全动态地创建它们,也可以这样做,反之亦然。更新您的问题,以获得迄今为止的HTML。试着更好地解释它。你为什么要在文本字段上转发??你会把文本字段放在一个单元格里,对吗?这意味着您正在自定义UITableViewCell。告诉我您是如何将文本字段添加到单元格中的?嗨。。我们在运行时创建,字段的数量可能会根据数组中对象的数量而变化。因此,请帮助我在上述给定的方法中获取标记。我没有获取标记分配,它是第一个文本字段还是第四个文本字段。嘿,你能更详细地解释一下吗?我正在动态创建文本字段,现在我在表中有两个部分,我希望在第1节下,所有的textfield值都应该在一个数组中得到add,在另一个数组中得到另一个section textfield值,因为我想要标记,所以我可以给出条件我没有得到如何做//在委托方法中,只需检查(theDelegateTextField==yourTextField){//在这里做点什么}