0

嗨,我试图在标签中显示来自 SQLite 的名称和电子邮件,从tableView到下一个视图,但在我的日志消息中,我只得到名称和标签名称,标签电子邮件为空。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *MyIdentifier = @"MyCell";
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell==nil) {
        cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault 
                                    reuseIdentifier:MyIdentifier];
    }
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    user *worddc=[Array objectAtIndex:[indexPath row]];
    cell.textLabel.text = worddc.name;
    profileVC *pvc =[[profileVC alloc]init];

    NSLog(@"name is  %@",worddc.name);

    pvc.nameLbl.text=worddc.name;

    NSLog(@"email is  %@",worddc.email);
    NSLog(@"label name is %@",pvc.nameLbl.text);

    pvc.emailLbl.text=worddc.email;

    NSLog(@"label email is %@",pvc.emailLbl.text);

    return cell;
} 

在日志消息中:

2012-12-07 17:02:28.720 loginApp[1881:c07] CONNECTION SUCCESSFUL WITH DB
2012-12-07 17:02:36.628 loginApp[1881:c07] QUERY: select email,password from login where email ='a@a.com' and password ='a'
2012-12-07 17:02:36.664 loginApp[1881:c07] QUERY: SELECT login.Name,login.id,login.Email FROM login ORDER BY login.Name ASC, login.id ASC
2012-12-07 17:02:36.667 loginApp[1881:c07] QUERY: select last_insert_rowid() 
2012-12-07 17:02:38.010 loginApp[1881:c07] id 6 
2012-12-07 17:02:38.011 loginApp[1881:c07] name is  a
2012-12-07 17:02:38.011 loginApp[1881:c07] email is  (null)
2012-12-07 17:02:38.012 loginApp[1881:c07] label name is (null)
2012-12-07 17:02:38.017 loginApp[1881:c07] label email is (null)

请问有什么帮助或建议吗?

4

4 回答 4

0

worddc 是否有效(不是零)?数组呢?

于 2012-12-07T12:52:28.763 回答
0

您是否尝试从笔尖加载视图控制器?如果是这样,您需要在 profileVC 上调用 – initWithNibName:bundle: 而不仅仅是 init。

于 2012-12-07T12:36:09.027 回答
0

您应该在其中实现profileVC调用方法,- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath:因为cellForRowAtIndexPath每次都会调用数据库中的最多行数,并且您正在初始化 pvc,cellForRowAtIndexPath其中在每个循环中 pvc 的范围都超出了范围。所以实现这个调用

profileVC *pvc =[[profileVC alloc]init];

NSLog(@"name is  %@",worddc.name);

pvc.nameLbl.text=worddc.name;

NSLog(@"email is  %@",worddc.email);
NSLog(@"label name is %@",pvc.nameLbl.text);

pvc.emailLbl.text=worddc.email;

NSLog(@"label email is %@",pvc.emailLbl.text);
于 2012-12-07T12:43:38.837 回答
0

profileVC *pvc =[[profileVC alloc]init]; 当您分配新视图时,它会在类中创建和分配新的所有值都为空它只加载视图确实加载并加载视图不加载其他方法

于 2012-12-07T13:17:17.120 回答