2011-08-03 7 views
-1

私はテーブル内のすべてのセルをループしています。各セルにはUITextFieldが含まれています。私はテキストフィールドのデータを検証したいが、私はテーブルの最初の行から有効な文字列を取得します。他のすべての行は、そのテキストとしてnullを返します。何か案は?あなたが行として可変そして部として可変を送信方法cellForRowAtIndexPathを通して細胞を得ることにUITableViewのセルをループするのが最初の行でのみ機能するのはなぜですか?

-(IBAction)saveContactToDB:(UIBarButtonItem *)sender 
    { 
     //TODO Loop through each row and test the data. 
     //  At least one name has to be entered. If this fails a UIAlert is prompted; otherwise, write to DB 
     NSLog(@"Attempting to save contact"); 
     NSInteger contactID; 
     for (NSInteger section = 0; section < [_contactInfoTable numberOfSections]; ++section) 
     { 
      for (NSInteger row = 0; row < [_contactInfoTable numberOfRowsInSection:section]; ++row) 
      { 
       ContactFieldCell *cell = (ContactFieldCell *)[_contactInfoTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:section 
                                 inSection:row]]; 
       NSLog(@"%@", cell.cellTextField.text); 
       NSLog(@"%@", cell.cellTextField.placeholder); 

       //Make sure at least one name is entered 
       //When i = 0 && j = 0 it means we are on the first row of the name section 
       if (section == 0 && row ==0 && cell.cellTextField.text == @"") 
       { 
        NSLog(@"Name is required"); 
        //Present alert 
        goto ALERTSHOWN; 
       } 
       else 
       { 
        //Write the data to the DB in its respective place 
        if (section == 0) 
        { 
         //Names 
         contactID = [APP.localDatabase saveContactName:cell.cellTextField.text]; 
        } 
        else if (section == 1) 
        { 
         //Position 
         [APP.localDatabase saveContactInfoValue:cell.cellTextField.text 
                 WithType:POSITION 
                ForContact:contactID 
                 AtOrder:row]; 
        } 
        else if (section == 2) 
        { 
         //Schedule 
         [APP.localDatabase saveContactInfoValue:cell.cellTextField.text 
                 WithType:SCHEDULE 
                ForContact:contactID 
                 AtOrder:row]; 
        } 
        else if (section == 3) 
        { 
         //Phone number 
         [APP.localDatabase saveContactInfoValue:cell.cellTextField.text 
                 WithType:PHONE 
                ForContact:contactID 
                 AtOrder:row]; 
        } 
        else if (section == 4) 
        { 
         //Miscellaneous 
         [APP.localDatabase saveContactInfoValue:cell.cellTextField.text 
                 WithType:MISCELLANEOUS 
                ForContact:contactID 
                 AtOrder:row]; 
        } 
       } 
      } 
     } 
     [self.view removeFromSuperview]; 
     ALERTSHOWN:; 
    } 
+0

:それがあるべきである ContactFieldCell *細胞=(ContactFieldCell *)[_ contactInfoTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:セクションinSection:行が]。 楽しい間違い... – crzrcn

答えて

1

。私は行とセクションの値を反転

ContactFieldCell *cell = (ContactFieldCell *)[_contactInfoTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]]; 
関連する問題