皆さんこんにちは、私は iOS 初心者です。私の質問は:
Mutable 配列とテーブルビューがあります。テーブル ビューの行数のカウントは、配列のカウントです。最後の行に何か入力すると、新しい行が作成されます。私が達成したいのは、行のいずれかが空白のままになっている場合、その行は自動的に削除されることです。前もって感謝します
@interface SubClassCell : UITableViewCell <UITextFieldDelegate>{
UILabel *lblShowFirst;
UITextField *txtShow;
id<SubclassDelegate> delegate;
NSArray *arrayFirstSection;
NSArray *arraySecondSection;
UILabel *lblShowSecond;
}
@property (nonatomic, retain) UILabel *lblShowFirst;
@property (nonatomic, retain) UILabel *lblShowSecond;
@property (nonatomic, retain) UITextField *txtShow;
@property (nonatomic, assign) id<SubclassDelegate> delegate;
@property (nonatomic, retain) NSArray *arrayFirstSection;
@property (nonatomic, retain) NSArray *arraySecondSection;
-(void) setCellTable:(NSIndexPath *) indexPath;
@end
@protocol SubclassDelegate <NSObject>
-(void)getTxtField:(NSString *)txtValue;
-(void)insertNewRows:(UITextField *)textF;
-(void)removeNewRows:(UITextField *)textF;
@end
subclass.m
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[txtShow resignFirstResponder];
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSLog(@"%@",textField.text);
if([textField.text length] == 1)
[self.delegate insertNewRows:textField];
else if ([textField.text length]==2){
[self.delegate removeNewRows:textField];
}
//if([textField.text length]==0){
// [self.delegate removeNewRows:textField];
// }
return YES;
}
Main class.m
-(void)insertNewRows:(UITextField *)textF
{
[arrayTagFirst addObject:textF.text];
[tableNewContactFirst beginUpdates];
[tableNewContactFirst insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath ndexPathForRow:[arrayTagFirst count]-1 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
[tableNewContactFirst endUpdates];
if (textF.editing && textF.text==0) {
[arrayTagFirst removeLastObject];
[tableNewContactFirst beginUpdates];
}
}