Monday 15 June 2015

ios - How do you get the indexPath of the cell you are tapping? -



ios - How do you get the indexPath of the cell you are tapping? -

i trying execute ibaction when long-press performed on cell in uitableview. action involves content of cell need indexpath in order retrieve content dictionary in local storage. ibaction method defined in masterviewcontroller.m file contains uitableview methods , subclassed uitableviewcontroller. have tried of following, , homecoming null instead of indexpath cell.

uitableviewcell *cell = (uitableviewcell *)self; nsindexpath *indexpath = [self.tableview indexpathforcell:cell]; nsindexpath *indexpath = [self.tableview indexpathforcell:sender]; nsindexpath *indexpath = [self.tableview indexpathforselectedrow];

i have seen few years-old answers similar questions utilize position of cell in view, can't of work either.

update: ibaction, sendtopb, beingness defined in subclass of uitableviewcontroller. there long-press gesture recognizer added cell in interface builder, sent actions connected sendtopb. action supposed copying content of cell clipboard when long-press on cell in table view. ways have tried far homecoming null indexpath.

- (ibaction)sendtopb:(id)sender { nsindexpath *indexpath = [self.tableview indexpathforcell:sender]; nsstring *object = self.objects[indexpath.row]; uipasteboard *pb = [uipasteboard generalpasteboard]; nsstring *pressedcelltext = [[data getallnotes] objectforkey:object]; [pb setstring: pressedcelltext]; }

update: have found 2 problems approach. first, long-press gesture doesn't select row, why of options used indexpathforselectedrow don't work. second, sender gesture recognizer, , not cell or row, using sender produces null value indexpath. these 2 factors in mind, how else can observe cell performed long-press on?

declare variable 1st in .h file nsindexpath *hitindex;

then on long press method u can position of cell & hence indexpath

(void)longpressmethod:(uibutton *)btn { cgpoint hitpoint = [btn convertpoint:cgpointzero toview:tbl_traits]; hitindex = [tbl_traits indexpathforrowatpoint:hitpoint]; }

ios uitableview ibaction nsindexpath

No comments:

Post a Comment