小编Ani*_*nil的帖子

自定义标签Cell的didSelectRowAtIndexPath

我正在使用此方法添加UILabel到我UITableView和它的工作正常,但我还需要创建一个方法来选择行并保存到临时字符串.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                             reuseIdentifier:CellIdentifier];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10,10, 300, 30)];
    [cell.contentView addSubview:label];
    label.text = [tableArr objectAtIndex:indexPath.row];
    label.font = [UIFont fontWithName:@"Whitney-Light" size:20.0];
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用.当我使用cell.textLabel而不是自定义标签时,它工作得很好.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell1 = [tableView cellForRowAtIndexPath:indexPath];
    UILabel *lbltemp = cell1.textLabel;

    _parent.labelone.text = lbltemp.text;       
}
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

5
推荐指数
1
解决办法
1万
查看次数

方法的空返回类型之间的差异

任何人都可以建议我之间有什么区别

- (void)tabtwoAction:(id)sender;
Run Code Online (Sandbox Code Playgroud)

- ()tabtwoAction:(id)sender;
Run Code Online (Sandbox Code Playgroud)

没有返回类型

objective-c

2
推荐指数
1
解决办法
83
查看次数

标签 统计

objective-c ×2

ios ×1

uitableview ×1