ios - subclassing uitextfield with shouldChangeCharactersInRange to handle max length not working -



ios - subclassing uitextfield with shouldChangeCharactersInRange to handle max length not working -

hello have searched many thread here subclassing uitextfield shouldchangecharactersinrange handle max length.

tried these next thread still not work: - how subclass uitextfield in ios? - uitextfield shouldchangecharactersinrange delgate not working - set custom uitextfield max length

my code bellow.

.h

//uitextfieldgeneral.h #import <uikit/uikit.h> @interface uitextfieldgeneral : uitextfield <uitextfielddelegate>{ int maxlength; } -(void)inisialisasi:(int)maxvalue; @end

.m

//uitextfieldgeneral.m #import "uitextfieldgeneral.h" @implementation uitextfieldgeneral - (id)initwithframe:(cgrect)frame { self = [super initwithframe:frame]; if (self) { // initialization code // self.delegate = self; } homecoming self; } -(void)inisialisasi:(int)maxvalue{ // self.keyboardtype = uikeyboardtypedecimalpad; self.textcolor = [uicolor blackcolor]; self.font = [uifont fontwithname:fontname size:fontsizeh3]; self.tintcolor = [uicolor blackcolor]; [self setbackgroundcolor:[uicolor whitecolor]]; [self setborderstyle:uitextborderstyleroundedrect]; [self settextalignment:nstextalignmentright]; maxlength = maxvalue; } - (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring*)string{ if (range.location >= maxlength) homecoming no; homecoming yes; }

code in viewcontroller

.h

@interface transferinterndaftarrekviewcontroller : tableviewcontrollercustomforinput<uitextfielddelegate>{

.m

tfberita = [[uitextfieldgeneral alloc] initwithframe:(cgrect){xlbl+widthlbl+20,5,widthlbl,30}]; tfberita.keyboardtype = uikeyboardtypedefault; [tfberita inisialisasi:20]; //tfberita.delegate = tfberita; tfberita.delegate = self;

shouldchangecharactersinrange method not called, if alter tfberita.delegate = self; tfberita.delegate = tfberita; give me error after typing 3 chars.

am missing something??

ios objective-c uitextfield

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -