我正在使用此方法添加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) 任何人都可以建议我之间有什么区别
- (void)tabtwoAction:(id)sender;
Run Code Online (Sandbox Code Playgroud)
和
- ()tabtwoAction:(id)sender;
Run Code Online (Sandbox Code Playgroud)
没有返回类型