我是iOS应用程序开发的新手,我需要有关UItableview的帮助。因为我用json数据填充表视图。我也使用Customized Tableviewcell。 我没有在“lbluid”上获得所选单元格的“huid”值。 “lbluid”根据滚动显示“huid”的值,因为我将向上滚动它将显示UITableview的最上面可见单元格的“huid”值,如果我向下滚动它将显示last的“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
。
答案 0 :(得分:11)
您可能必须实施该方法:
- (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
仅在滚动表视图时才会更改。
答案 1 :(得分:0)
在Swift中
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as! NotesCell!
let value = cell?.lblDetail.text
}