我是 iOS 应用程序开发新手,需要有关 UItableview 的帮助。当我用 json 数据填充表视图时。我也使用自定义的 Tableviewcell。
我没有得到“lbluid”上选定单元格的“huid”值。 “lbluid”根据滚动显示“huid”值,因为我将向上滚动它将显示 UITableview 的最上面可见单元格的“huid”值,如果我向下滚动它将显示最后一个的“huid”值从下往上可见细胞。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableCell";
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];;
}
NSUInteger row = [indexPath row];
cell.lbl4.text = [hudid objectAtIndex:row];
lbluid.text=cell.lbl4.text;
return cell;
}
Simpletablecell
是定制的UITableViewCell
.
您可能必须实现该方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
每次选择一行时都会调用该方法,并在该方法内部:
Simpletablecell *cell = (Simpletablecell *)[tableView cellForRowAtIndexPath:indexpath];
lbluid.text = cell.lbl4.text;
方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
被称为表视图正在加载要显示的单元格,这就是为什么你lbluid.text
仅当表视图滚动时才发生变化。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)