【发布时间】:2014-07-09 06:18:10
【问题描述】:
在我的 UIview 中,当单击文本字段时,我有 UITextField,然后我使用 UIPickerView。然后我选择值这个值进入文本字段。
现在我想当文本字段值改变时,表格行值改变。
我使用了以下代码
- (void)viewDidLoad:
{
[super viewDidLoad];
[self loadCriteria];
UILabel * projectDetailLable = [[UILabel alloc] initWithFrame:CGRectMake(0,[topBar bottom],320, 30)];
projectDetailLable.textColor = [UIColor whiteColor];
projectDetailLable.backgroundColor = UIColorFromRGB(0x28a0d8);
projectDetailLable.font = [UIFont boldSystemFontOfSize:16];
projectDetailLable.text = @"Choose Criteria Category:";
projectDetailLable.textAlignment = NSTextAlignmentLeft;
[self.view addSubview:projectDetailLable];
criteriaTextField = [[UITextField alloc] initWithFrame:CGRectMake(2, [projectDetailLable bottom]+2, 316, 30)];
criteriaTextField.borderStyle = UITextBorderStyleLine;
// criteriaTextField.text = @"Health & Well being";
criteriaTextField.font = [UIFont systemFontOfSize:13];
[self.view addSubview:criteriaTextField];
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = criteriaTextField.frame;
[button addTarget:self action:@selector(launchCriteriaPicker) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
caseStudyTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, [criteriaTextField bottom]+5, 320, self.view.frame.size.height )];
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")){
[caseStudyTableView setSeparatorInset:UIEdgeInsetsZero];
}
caseStudyTableView.delegate = self;
caseStudyTableView.dataSource = self;
caseStudyTableView.rowHeight = 40;
caseStudyHeaderView.backgroundColor = [UIColor clearColor];
[self.view addSubview:caseStudyTableView];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[ cell.textLabel setFont:[UIFont boldSystemFontOfSize:13]];
[ cell.textLabel setTextAlignment:NSTextAlignmentLeft];
cell.textLabel.numberOfLines=0;
[ cell.textLabel setTextColor:[UIColor blackColor]];
cell.textLabel.backgroundColor = UIColorFromRGB(0xc8f898);
cell.contentView.backgroundColor = UIColorFromRGB(0xc8f898);
NSLog(@"%@",criteriaNameArray);
cell.textLabel.text = [criteriaNameArray objectAtIndex:indexPath.row];
return cell;
}
如何更改IOS 中的表值。
【问题讨论】:
-
请澄清你的问题。
-
选择器和表格视图是否使用相同的数组?
-
您将尝试显示您是否在选择器视图中选择了 3 行并将该值添加到文本字段中,以便第三行数据自动显示在 tableview 中?我说的对吗?
-
darshan 对,我只想要这种方式
标签: ios uitableview uitextfield uipickerview