ios - Content not displaying on UITableViewCell -
i attempting create autosizing cell using purelayout, though json loads , correctly assigned uitableviewcell objects no data displayed.
here how attempting setup cell in custom tableviewcell class:
self.backgroundcolor = [uicolor whitecolor]; self.accessorytype = uitableviewcellaccessorynone; self.accessoryview = nil; self.selectionstyle = uitableviewcellselectionstylenone; // fix contentview constraint warning [self.contentview setautoresizingmask:uiviewautoresizingflexibleheight]; // create profileimageview self.profilepicture = [[uiimageview alloc] initwithframe:cgrectzero]; self.profilepicture.translatesautoresizingmaskintoconstraints = no; self.profilepicture.contentmode = uiviewcontentmodescaleaspectfill; self.profilepicture.backgroundcolor = [uicolor whitecolor]; [self.contentview addsubview:self.profilepicture]; // name label self.namelabel = [[uilabel alloc] initwithframe:cgrectzero]; self.namelabel.translatesautoresizingmaskintoconstraints = no; self.namelabel.font = [uifont fontwithname:@"helveticaneue-medium" size:16]; self.namelabel.textcolor = [uicolor blackcolor]; self.namelabel.numberoflines = 1; [self.contentview addsubview:self.namelabel]; // username label self.usernamelabel = [[uilabel alloc] initwithframe:cgrectzero]; self.usernamelabel.translatesautoresizingmaskintoconstraints = no; self.usernamelabel.font = [uifont fontwithname:@"helveticaneue-light" size:14]; self.usernamelabel.textcolor = [uicolor darkgraycolor]; self.usernamelabel.numberoflines = 1; [self.contentview addsubview:self.usernamelabel]; // tweet label self.tweetlabel = [[uilabel alloc] initwithframe:cgrectzero]; self.tweetlabel.userinteractionenabled = yes; self.tweetlabel.translatesautoresizingmaskintoconstraints = no; self.tweetlabel.numberoflines = 0; // must set multi-line label work self.tweetlabel.linebreakmode = nslinebreakbywordwrapping; self.tweetlabel.font = [uifont fontwithname:@"helveticaneue" size:14]; self.tweetlabel.textcolor = [uicolor darkgraycolor]; [self.contentview addsubview:self.tweetlabel]; // favorite button self.favoritebutton = [[dofavoritebutton alloc] initwithframe:cgrectzero image:[uiimage imagenamed:@"star.png"] imageframe:cgrectmake(0, 0, 15, 15)]; [self.contentview addsubview:self.favoritebutton]; // retweet button self.retweetbutton = [[dofavoritebutton alloc] initwithframe:cgrectzero image:[uiimage imagenamed:@"retweet.png"] imageframe:cgrectmake(0, 0, 15, 15)]; self.retweetbutton.circlecolor = [uicolor colorwithred:0.04 green:0.83 blue:0.04 alpha:1.0]; self.retweetbutton.linecolor = [uicolor colorwithred:0.08 green:0.93 blue:0.08 alpha:1.0]; self.retweetbutton.imagecoloron = [uicolor colorwithred:0.26 green:0.96 blue:0.26 alpha:1.0]; [self.contentview addsubview:self.retweetbutton]; // reply button self.replybutton = [[dofavoritebutton alloc] initwithframe:cgrectzero]; [self.replybutton setbackgroundimage:[uiimage imagenamed:@"reply.png"] forstate:uicontrolstatenormal]; [self.contentview addsubview:self.replybutton]; // // constrain // // name label [self.namelabel autopinedgetosuperviewedge:aledgeleft withinset:60]; [self.namelabel autopinedgetosuperviewedge:aledgeright withinset:35]; [self.namelabel autopinedgetosuperviewedge:aledgetop withinset:12]; [self.namelabel autoalignaxis:alaxisvertical tosameaxisofview:self.contentview]; // username label [self.usernamelabel autopinedge:aledgetop toedge:aledgebottom ofview:self.namelabel withoffset:0.0]; [self.usernamelabel autosetdimension:aldimensionheight tosize:16.5]; [self.usernamelabel autopinedgetosuperviewedge:aledgeleft withinset:58.0]; // profile picture [self.profilepicture autopinedge:aledgeright toedge:aledgeleft ofview:self.namelabel withoffset:-10.0]; [self.profilepicture autopinedgetosuperviewedge:aledgetop withinset:12]; [self.profilepicture autosetdimension:aldimensionheight tosize:35]; [self.profilepicture autosetdimension:aldimensionwidth tosize:35]; // tweet label [self.tweetlabel autopinedge:aledgetop toedge:aledgebottom ofview:self.usernamelabel withoffset:8.0]; [self.tweetlabel autopinedgetosuperviewedge:aledgeleft withinset:5.0];
here how initiate cell in uitableviewcontroller:
twittercell *cell = [self.tableview dequeuereusablecellwithidentifier:@"twittercell"]; // add tap listeners uitapgesturerecognizer *namelabeltap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handlecellnametap:)]; [cell.namelabel addgesturerecognizer:namelabeltap]; uitapgesturerecognizer *profileimagetap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handlecellprofileimagetap:)]; [cell.profilepicture addgesturerecognizer:profileimagetap]; if (cell == nil) { cell = [[twittercell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"twittercell"]; } nsdictionary *data = tweets[indexpath.row]; // nsdate nsstring *namestring = data[@"user"][@"name"]; nsstring *screenname = data[@"user"][@"screen_name"]; nsstring *tweetstring = data[@"text"]; nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; nslocale *uslocale = [[nslocale alloc] initwithlocaleidentifier:@"en_us"]; [dateformatter setlocale:uslocale]; [dateformatter setdatestyle:nsdateformatterlongstyle]; [dateformatter setformatterbehavior:nsdateformatterbehavior10_4]; [dateformatter setdateformat: @"eee mmm dd hh:mm:ss z yyyy"]; nsdate *date = [dateformatter datefromstring:[data objectforkey:@"created_at"]]; nsdate *currentdatentime = [nsdate date]; nscalendar *calendar = [nscalendar currentcalendar]; [calendar settimezone:[nstimezone timezonewithabbreviation:@"gmt"]]; nsdatecomponents *twitcomponents = [calendar components:(nscalendarunithour | nscalendarunitminute | nscalendarunitsecond) fromdate:date]; nsinteger twithour = [twitcomponents hour]; nsinteger twitminute = [twitcomponents minute]; nsinteger twitsecond = [twitcomponents second]; nsdatecomponents *realcomponents = [calendar components:(nscalendarunithour | nscalendarunitminute | nscalendarunitsecond) fromdate:currentdatentime]; nsinteger realhour = [realcomponents hour]; nsinteger realminute = [realcomponents minute]; nsinteger realsecond = [realcomponents second]; nsinteger hour = realhour - twithour; nsinteger minute = realminute - twitminute; nsinteger second = realsecond - twitsecond; nslog(@"formatted hour: %ld, formatted minute: %ld, formatted second: %ld",(long)hour, (long)minute, (long)second); int adjustedseconds = ((int)minute * 60) - abs((int)second); int adjustedminutes = adjustedseconds / 60; if (hour==1 > minute > 0) { int negmin = ((int)hour * 60) - abs((int)minute); int posmin = abs(negmin); nsstring *strint = [nsstring stringwithformat:@"%dm",posmin]; cell.timeago.text = strint; }else if (hour>0){ nsstring *strint = [nsstring stringwithformat:@"%ldh",(long)hour]; cell.timeago.text = strint; }else if (hour==1){ nsstring *strint = [nsstring stringwithformat:@"%ldh",(long)hour]; cell.timeago.text = strint; }else if(minute == 1 > second){ nsstring *strint = [nsstring stringwithformat:@"%lds",(long)second]; cell.timeago.text = strint; }else{ nsstring *strfromint = [nsstring stringwithformat:@"%dm",adjustedminutes]; cell.timeago.text = strfromint; } [cell.favoritebutton addtarget:self action:@selector(favoritebuttontapped:) forcontrolevents:uicontroleventtouchupinside]; [cell.retweetbutton addtarget:self action:@selector(retweetbuttontapped:) forcontrolevents:uicontroleventtouchupinside]; // set values [cell.namelabel settext:namestring]; cell.namelabel.userinteractionenabled = yes; cell.profilepicture.userinteractionenabled = yes; cell.tweetlabel.text = tweetstring; cell.usernamelabel.text = [nsstring stringwithformat:@"@%@",screenname]; dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{ nsstring *imageurl = [[data objectforkey:@"user"] objectforkey:@"profile_image_url"]; nsdata *data = [nsdata datawithcontentsofurl:[nsurl urlwithstring:imageurl]]; dispatch_async(dispatch_get_main_queue(), ^{ cell.profilepicture.image = [uiimage imagewithdata:data]; calayer *imagelayer = cell.profilepicture.layer; [imagelayer setcornerradius:18]; [imagelayer setmaskstobounds:yes]; }); });
is tableview's delegate
, datasource
set? can setting:
self.tableview.delegate = self; self.tableview.datasource = self;
in viewdidload
method.
and running numberofsectionsintableview:
, numberofrowsinsection:
methods also?
i assume initializing cell in cellforrowatindexpath:
, , remember return cells in there?
Comments
Post a Comment