【发布时间】:2013-12-02 08:23:57
【问题描述】:
你好朋友请解决我的问题
我有两个 xib ,一个 xib 有文本字段,另一个有 tableview 包含来自 sqlite 的数据。
当我单击 tableview 的单元格时,它会将数据存储到字符串对象中,并且该字符串对象在包含文本字段的 .m 文件中使用。
但文本字段未显示文本..
我检查了所有的东西,比如文字颜色、背景等等……但还是有问题……
我分配简单的文本,如
nametextfield.text=@"hello";
但是上面的代码也没有工作。
我在应用程序中的真正编码在这里:
//tableviewcontroller.m
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
cell.textLabel.text=[[data objectAtIndex:indexPath.row] valueForKey:@
"name"];
cell.detailTextLabel.text=[[data objectAtIndex:indexPath.row]
valueForKey:@"salary"];
return cell;
}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ViewController *vc=[[ViewController alloc]init];
nameStr =[[data objectAtIndex:indexPath.row] valueForKey:@"name"];
salaryStr=[[data objectAtIndex:indexPath.row] valueForKey:@"salary"];
NSLog(@"%@ %@",nameStr,salaryStr); //i got the value here
[vc fillTextfield:nameStr:salaryStr];
[self.navigationController popToRootViewControllerAnimated:YES];
}
//viewcontroller.m
-(void)fillTextfield:(NSString*)nm:(NSString*)sal
{
NSLog(@"string : %@ %@ ",nm,sal);// i also got the value here
name.text=nm;
salary.text=sal;
//but after this code textfield not shown the text ... :(
}
我该怎么办??????
【问题讨论】:
-
显示你是如何定义 UITextfield 的代码?
-
直接把uitextfield放到xib文件中
-
也做了引用出口和委托
-
然后显示CellforRowAtIndexPath的代码?
-
在 CellforRowAtIndexPath 处为 textField 添加委托,并将 UitableViewCellSelection 禁用为 none..
标签: ios objective-c uitableview ios7 xcode5