objective c - Cannot click on TableView cell. (iOS, Custom cell implementation) -



objective c - Cannot click on TableView cell. (iOS, Custom cell implementation) -

i have table view list of article titles. have implemented functions delete , archive articles swipes (left swipe - archive, right swipe - delete). works great (like application called "clear" on iphone). then, have been dragged cell (holding ctrl button) new view controller (where have label, imageview , textview) display article (push). however, somehow cells not clickable. can swipes no problem, cannot click , go next view controller. have used - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender setting info display. also, used tutorial configure cell. have included implementation well. suppose, problem, not know how code, configuring cell works. cause of such behaviour? give thanks you.

the code inboxviewcontroller.m (the 1 has tableview):

. . . #pragma mark view - (void) viewwillappear:(bool)animated { [super viewwillappear:animated]; [self.db opendatabase]; nsstring* date_added = [self.db getlastarticledate]; [self makeconnetion:(id)date_added]; nslog(@"viewwillappear: self.articles: %d", self.articles.count); [self.db closedatabase]; } - (void)viewdidload { [super viewdidload]; self.tableview.datasource = self; self.tableview.delegate = self; self.tableview.separatorcolor = [uicolor clearcolor]; self.tableview.backgroundcolor = [uicolor blackcolor]; [self.tableview registerclass:[shctableviewcell class] forcellreuseidentifier:@"content"]; } #pragma mark - table view info source - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { // homecoming number of sections. homecoming 1; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { // homecoming number of rows in section. nslog(@"numberofrowsinsection: self.articles: %d", self.articles.count); homecoming self.articles.count; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"content"; shctableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath]; cell.textlabel.backgroundcolor = [uicolor clearcolor]; //nsmutablearray* safearticles = self.articles; // configure cell... article* article = [self.articles objectatindex:indexpath.row]; nsstring *listingkey = article.title; nsstring *listingvalues = article.url; cell.textlabel.text = listingkey; cell.detailtextlabel.text = listingvalues ; cell.delegate = self; cell.todoitem = article; homecoming cell; } #pragma mark cell atributes -(uicolor*)colorforindex:(nsinteger) index { nsuinteger itemcount = self.articles.count - 1; float val = ((float)index / (float)itemcount) * 0.6; homecoming [uicolor colorwithred: 1.0 green:val blue: 0.0 alpha:1.0]; } -(cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { homecoming 70.0f; } -(void)tableview:(uitableview *)tableview willdisplaycell:(uitableviewcell *)cell forrowatindexpath:(nsindexpath *)indexpath { cell.backgroundcolor = [self colorforindex:indexpath.row]; } #pragma mark todo delete server database //method delete article form view , phone call method delete database, form server database -(void)deletearticle:(article*)articletodelete { . . . } #pragma mark todo archive in server database //method delete article form view , phone call method delete database, form server database -(void)archivearticle:(article*)articletoarchive { . . . } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([segue.identifier isequaltostring:@"articleview"]) { articleviewcontroller* articleview = (articleviewcontroller*) segue.destinationviewcontroller; nsindexpath *indexpath = [self.tableview indexpathforcell:sender]; nsinteger index = indexpath.row; article *article = [self.articles objectatindex:index]; articleview.article_title.text = article.title; articleview.article_content.text = article.content; } }

shctableviewcell.m (configures cell)

// // shctableviewcell.m // clearstyle // // created fahim farook on 23/9/12. // copyright (c) 2012 rooksoft pte. ltd. rights reserved. // #import "shctableviewcell.h" #import <quartzcore/quartzcore.h> @implementation shctableviewcell { cagradientlayer* _gradientlayer; cgpoint _originalcenter; bool _deleteondragrelease; calayer *_itemcompletelayer; bool _markcompleteondragrelease; uilabel *_ticklabel; uilabel *_crosslabel; } const float ui_cues_margin = 20.0f; const float ui_cues_width = 50.0f; -(id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier { self = [super initwithstyle:style reuseidentifier:reuseidentifier]; if (self) { // add together tick , cross _ticklabel = [self createcuelabel]; _ticklabel.text = @"archive"; _ticklabel.textalignment = nstextalignmentright; [self addsubview:_ticklabel]; _crosslabel = [self createcuelabel]; _crosslabel.text = @"delete"; _crosslabel.textalignment = nstextalignmentleft; [self addsubview:_crosslabel]; // create label renders todo item text // remove default bluish highlight selected cells self.selectionstyle = uitableviewcellselectionstylenone; // add together layer overlays cell adding subtle gradient effect _gradientlayer = [cagradientlayer layer]; _gradientlayer.frame = self.bounds; _gradientlayer.colors = @[(id)[[uicolor colorwithwhite:1.0f alpha:0.2f] cgcolor], (id)[[uicolor colorwithwhite:1.0f alpha:0.1f] cgcolor], (id)[[uicolor clearcolor] cgcolor], (id)[[uicolor colorwithwhite:0.0f alpha:0.1f] cgcolor]]; _gradientlayer.locations = @[@0.00f, @0.01f, @0.95f, @1.00f]; [self.layer insertsublayer:_gradientlayer atindex:0]; // add together layer renders greenish background when item finish _itemcompletelayer = [calayer layer]; _itemcompletelayer.backgroundcolor = [[[uicolor alloc] initwithred:0.0 green:0.6 blue:0.0 alpha:1.0] cgcolor]; _itemcompletelayer.hidden = yes; [self.layer insertsublayer:_itemcompletelayer atindex:0]; // add together pan recognizer uigesturerecognizer* recognizer = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(handlepan:)]; recognizer.delegate = self; [self addgesturerecognizer:recognizer]; } homecoming self; } const float label_left_margin = 20.0f; -(void)layoutsubviews { [super layoutsubviews]; // ensure gradient layers occupies total bounds _gradientlayer.frame = self.bounds; _itemcompletelayer.frame = self.bounds; _ticklabel.frame = cgrectmake(-ui_cues_width - ui_cues_margin, 0, ui_cues_width, self.bounds.size.height); _crosslabel.frame = cgrectmake(self.bounds.size.width + ui_cues_margin, 0, ui_cues_width, self.bounds.size.height); } -(void)settodoitem:(article *)todoitem { _todoitem = todoitem; // must update visual state associated model item //_label.text = todoitem.text; _itemcompletelayer.hidden = !todoitem.completed; } // utility method creating contextual cues -(uilabel*) createcuelabel { uilabel* label = [[uilabel alloc] initwithframe:cgrectnull]; label.textcolor = [uicolor whitecolor]; label.font = [uifont boldsystemfontofsize:15.0]; label.backgroundcolor = [uicolor clearcolor]; homecoming label; } #pragma mark - horizontal pan gesture methods -(bool)gesturerecognizershouldbegin:(uipangesturerecognizer *)gesturerecognizer { cgpoint translation = [gesturerecognizer translationinview:[self superview]]; // check horizontal gesture if (fabsf(translation.x) > fabsf(translation.y)) { homecoming yes; } homecoming no; } -(void)handlepan:(uipangesturerecognizer *)recognizer { if (recognizer.state == uigesturerecognizerstatebegan) { // if gesture has started, record current centre location _originalcenter = self.center; } if (recognizer.state == uigesturerecognizerstatechanged) { // translate center cgpoint translation = [recognizer translationinview:self]; self.center = cgpointmake(_originalcenter.x + translation.x, _originalcenter.y); // determine whether item has been dragged far plenty initiate delete / finish _markcompleteondragrelease = self.frame.origin.x > self.frame.size.width / 2; _deleteondragrelease = self.frame.origin.x < -self.frame.size.width / 2; // context cues // fade contextual cues float cuealpha = fabsf(self.frame.origin.x) / (self.frame.size.width / 2); _ticklabel.alpha = cuealpha; _crosslabel.alpha = cuealpha; // indicate when item have been pulled far plenty invoke given action _ticklabel.textcolor = _markcompleteondragrelease ? [uicolor greencolor] : [uicolor whitecolor]; _crosslabel.textcolor = _deleteondragrelease ? [uicolor redcolor] : [uicolor whitecolor]; } if (recognizer.state == uigesturerecognizerstateended) { // frame cell have had before beingness dragged cgrect originalframe = cgrectmake(0, self.frame.origin.y, self.bounds.size.width, self.bounds.size.height); if (!_deleteondragrelease) { // if item not beingness deleted, snap original location [uiview animatewithduration:0.2 animations:^{ self.frame = originalframe; } ]; } if (_deleteondragrelease) { // notify delegate item should deleted [self.delegate deletearticle:self.todoitem]; } if (!_markcompleteondragrelease) { // if item not beingness deleted, snap original location [uiview animatewithduration:0.2 animations:^{ self.frame = originalframe; } ]; } if (_markcompleteondragrelease) { // mark item finish , update ui state self.todoitem.completed = yes; [self.delegate archivearticle:self.todoitem]; } } } @end

use tableview delegate method if want action after clicking tableview cell

-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { nslog(@"selected cell"); }

ios objective-c uitableview tableview

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -