0

こんにちは、SQLiteからの名前と電子メールtableViewを次のビューのラベルに表示しようとしていますが、ログメッセージに名前とラベル名しか表示されません。ラベルの電子メールはnullです。

- (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

データベース内の行数まで毎回呼び出すため、profileVC呼び出しメソッドを実装する必要があります。また、すべてのループで pvc のスコープが範囲外である pvc を初期化しています。この呼び出しを実装します- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath:cellForRowAtIndexPathcellForRowAtIndexPath

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

nib から View Controller を読み込もうとしていますか? その場合は、init だけでなく、profileVC で –initWithNibName:bundle: を呼び出す必要があります。

于 2012-12-07T12:36:09.027 に答える
0

worddc は有効ですか (nil ではありません)? アレイはどうですか?

于 2012-12-07T12:52:28.763 に答える
0

profileVC *pvc =[[profileVC alloc]init]; 新しいビューを割り当てるときに、クラスで新しく作成して割り当てます。すべての値はnullです。ビューのみをロードし、ビューをロードし、ビューをロードし、他のメソッドをロードしません

于 2012-12-07T13:17:17.120 に答える