怎样获取UITabelView cell中的label的内容
2个回答
推荐于2016-01-26
展开全部
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"shoppingCell";
ShoppingGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[ShoppingGoodsCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellIdentifier];
}
else
{
while (cell.contentView.subviews.lastObject != nil) {
[cell.contentView.subviews.lastObject removeFromSuperview];
}
}
UILabel *goodsName = [[UILabel alloc]initWithFrame:CGRectMake(80, 2, 205, 45)];
goodsName.font = [UIFont fontWithName:@"Helvetica" size:12];
goodsName.numberOfLines = 2;
goodsName.text = @"sjogjeojgesjgpesgpsejgpespgjspengosehgespgkerpogepgjpeosgjespofgjpes";
UILabel *numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(80, 47, 205, 30)];
numberLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
numberLabel.text = [countArray objectAtIndex:indexPath.row];
numberLabel.tag = indexPath.row;
UILabel *countLabel = [[UILabel alloc]initWithFrame:CGRectMake(80, 70, 40, 30)];
countLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
countLabel.text = @"数量:";
//数量输入框
UITextField *countTxt = [[UITextField alloc]initWithFrame:CGRectMake(120, 74, 30, 20)];
countTxt.layer.cornerRadius = 5.0;
countTxt.layer.borderWidth = 0.5;
countTxt.tag = 110;
UILabel *uinitLabel = [[UILabel alloc]initWithFrame:CGRectMake(165, 70, 40, 30)];
uinitLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
uinitLabel.text = @"单价";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[cell.contentView addSubview:goodsName];
[cell.contentView addSubview:numberLabel];
[cell.contentView addSubview:countLabel];
[cell.contentView addSubview:countTxt];
[cell.contentView addSubview:uinitLabel];
return cell;
}
这个是要获取每一个cell中比如:goodsName,numberLabel,countLabel 的text。而且不是在did selected中实现的
{
static NSString *cellIdentifier = @"shoppingCell";
ShoppingGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[ShoppingGoodsCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellIdentifier];
}
else
{
while (cell.contentView.subviews.lastObject != nil) {
[cell.contentView.subviews.lastObject removeFromSuperview];
}
}
UILabel *goodsName = [[UILabel alloc]initWithFrame:CGRectMake(80, 2, 205, 45)];
goodsName.font = [UIFont fontWithName:@"Helvetica" size:12];
goodsName.numberOfLines = 2;
goodsName.text = @"sjogjeojgesjgpesgpsejgpespgjspengosehgespgkerpogepgjpeosgjespofgjpes";
UILabel *numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(80, 47, 205, 30)];
numberLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
numberLabel.text = [countArray objectAtIndex:indexPath.row];
numberLabel.tag = indexPath.row;
UILabel *countLabel = [[UILabel alloc]initWithFrame:CGRectMake(80, 70, 40, 30)];
countLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
countLabel.text = @"数量:";
//数量输入框
UITextField *countTxt = [[UITextField alloc]initWithFrame:CGRectMake(120, 74, 30, 20)];
countTxt.layer.cornerRadius = 5.0;
countTxt.layer.borderWidth = 0.5;
countTxt.tag = 110;
UILabel *uinitLabel = [[UILabel alloc]initWithFrame:CGRectMake(165, 70, 40, 30)];
uinitLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
uinitLabel.text = @"单价";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[cell.contentView addSubview:goodsName];
[cell.contentView addSubview:numberLabel];
[cell.contentView addSubview:countLabel];
[cell.contentView addSubview:countTxt];
[cell.contentView addSubview:uinitLabel];
return cell;
}
这个是要获取每一个cell中比如:goodsName,numberLabel,countLabel 的text。而且不是在did selected中实现的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询