
-(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 (cellcontentViewsubviewslastObject != nil) {
[cellcontentViewsubviewslastObject removeFromSuperview];
}
}
UILabel goodsName = [[UILabel alloc]initWithFrame:CGRectMake(80, 2, 205, 45)];
goodsNamefont = [UIFont fontWithName:@"Helvetica" size:12];
goodsNamenumberOfLines = 2;
goodsNametext = @"sjogjeojgesjgpesgpsejgpespgjspengosehgespgkerpogepgjpeosgjespofgjpes";
UILabel numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(80, 47, 205, 30)];
numberLabelfont = [UIFont fontWithName:@"Helvetica" size:12];
numberLabeltext = [countArray objectAtIndex:indexPathrow];
numberLabeltag = indexPathrow;
UILabel countLabel = [[UILabel alloc]initWithFrame:CGRectMake(80, 70, 40, 30)];
countLabelfont = [UIFont fontWithName:@"Helvetica" size:12];
countLabeltext = @"数量:";
//数量输入框
UITextField countTxt = [[UITextField alloc]initWithFrame:CGRectMake(120, 74, 30, 20)];
countTxtlayercornerRadius = 50;
countTxtlayerborderWidth = 05;
countTxttag = 110;
UILabel uinitLabel = [[UILabel alloc]initWithFrame:CGRectMake(165, 70, 40, 30)];
uinitLabelfont = [UIFont fontWithName:@"Helvetica" size:12];
uinitLabeltext = @"单价";
cellaccessoryType = UITableViewCellAccessoryDisclosureIndicator;
[cellcontentView addSubview:goodsName];
[cellcontentView addSubview:numberLabel];
[cellcontentView addSubview:countLabel];
[cellcontentView addSubview:countTxt];
[cellcontentView addSubview:uinitLabel];
return cell;
}
这个是要获取每一个cell中比如:goodsName,numberLabel,countLabel 的text。而且不是在did selected中实现的
1、因为UITableView有重用机制,它用两个数组用来存储UITableViewCell,一个是visibleCells,它保存屏幕上看到的cell,滑动tableview时如果一个cell移出屏幕了,它就会被从visibleCells中移出,同时放入到reusebleCells中,所以用cellForRowAtIndexPath是无法获取到。
2、按照你的代码,你没有使用dequeueReusableCellWithIdentifier来对cell进行重用,但是也并不会因为这样tableview就会为你alloc一次所有的cell,它依然是只会创建需要在屏幕上显示的cell。
3、如果是我,我会用一个数组来保存所有UITextField的值。
-(CGFloat)tableView:(UITableView )tableView heightForFooterInSection:(NSInteger)section{
return 100;
}
- (UIView )tableView:(UITableView )tableView viewForFooterInSection:(NSInteger)section{
UIView bgv = [[UIView alloc]initWithFrame:CGRectMake(0, 0, APPWIDTH, 10)];
bgvbackgroundColor = [UIColor colorWithWhite:5 alpha:1];
return bgv;
}
你把你添加的line删除 加到上述bgv里面
直接用tableview的datasource的numberOfSectionsInTableView和numberOfRowsInSection就可以取到最后一个cell的indexPath,再跟目标cell的indexPath一比就行了。
点击一个cell 高度增加,tableview初始化是4个cell的大小,当点击第四个cell的时候 高度增加了,cell里增加的部分在tableview的下面,看不到了,需要向上拖动tableview才行,这样用户体验不好。
现在的情况是,点击一个cell时,增加了高度,当点击的下一个cell在上次点击的cell的下面,高度增加的时候是向上的方向上增加的,如果在上次点击的cell上面就向下的方向增加,能不能自动判断当前cell在tableview中的位置,
根据当前位置决定增加高度的方向。
table view不会对所有行都生成CELL对象,展示时是重用的。当然如果你的行数不多,你可以不使用重用机制,为每行创建独立的CELL,并保存到自己的ARRAY,需要时自己遍历好了,不知道别的还有没有好的办法
一般的话- (UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath )indexPath 这个方法里应该都会设置cell内的显示内容,在didselect里面你把上面那个方法里的[xxxx objectAtIndex:indexPathrow] xxxxx]再次赋给你自己要取指的对象不就可以了么
一般的话- (UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath )indexPath 这个方法里应该都会设置cell内的显示内容,在didselect里面你把上面那个方法里的[xxxx objectAtIndex:indexPathrow] xxxxx]再次赋给你自己要取指的对象不就可以了么
以上就是关于怎样获取UITabelView cell中的label的内容全部的内容,包括:怎样获取UITabelView cell中的label的内容、如何捕获作为subview镶嵌在TableViewCell中TextField的值、如何拿到分组的tableview的每一组最后一个cell等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)