单击tableview或按钮时如何在我的标签中获得价值

时间:2012-12-07 12:34:29

标签: iphone ios xcode ipad

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

- (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 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

您应该在profileVC中实施- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath:调用方法,因为cellForRowAtIndexPath每次都会调用数据库中的行数,并且您正在cellForRowAtIndexPath中初始化pvc每个循环,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);

答案 2 :(得分:0)

worddc有效(不是零)吗?数组怎么样?

答案 3 :(得分:0)

profileVC * pvc = [[profileVC alloc] init];它创造了&在分配新视图时,在类中新分配所有valus为null它只加载视图加载和加载视图不加载其他方法