ios - UITableViewCell Custom Add to favourites button issue -
in table view, placed custom "add favs" button in every cell enable user copy exact cell content second tableview controller. when hit "add favs" button alert view shows ask if want copy cell , paste second view controller or not. there 2 things. 1- there way delete "add favs" button permanently cell if "ok" selected alert view indicate cell copied , pasted second tableview? - user won't able add cell content on , on again. 2- bigger question: how copy , paste cell content secondtableview controller "add favs" click?
here way cells re configured:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier]; nsstring* letter = [letters objectatindex:indexpath.section]; nsarray* arrayforletter = (nsarray*)[filteredtabledata objectforkey:letter]; songs* songs = (songs*)[arrayforletter objectatindex:indexpath.row]; cell.textlabel.text = songs.name; cell.detailtextlabel.text = songs.description; cgsize itemsize = cgsizemake(50, 50); uigraphicsbeginimagecontextwithoptions(itemsize, no, uiscreen.mainscreen.scale); cgrect imagerect = cgrectmake(0.0, 0.0, itemsize.width, itemsize.height); [cell.imageview.image drawinrect:imagerect]; cell.imageview.image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); uibutton *addtofavsbutton = [uibutton buttonwithtype:uibuttontyperoundedrect]; addtofavsbutton.frame = cgrectmake(200.0f, 5.0f, 105.0f, 70.0f); [addtofavsbutton setimage:[uiimage imagenamed:@"fav.png"] forstate:uicontrolstatenormal]; [addtofavsbutton settintcolor:[uicolor whitecolor]]; [cell addsubview:addtofavsbutton]; [addtofavsbutton addtarget:self action:@selector(addtofavs:) forcontrolevents:uicontroleventtouchupinside]; return cell; } - (ibaction)addtofavs:(id)sender { uialertview *alert = [[uialertview alloc]initwithtitle:@"dikkaaaat!" message:@"Şarkıyı favori akorlarınıza alıyorsunuz..." delegate:nil cancelbuttontitle:@"cancel" otherbuttontitles:@"ok", nil]; [alert show]; }
considering data in app only, , considering using regular table cell, not custom one, recommend is:
make new simple array in app called "myfavorites" or whatever, hold list of numerical values.
when user confirms add favorites, take current section , row indexes songs array, , store in new array.
in first view controller, add "cellforrowatindexpath" simple check see if song row exist in new array with.
something like:
if([[myfavorites objectatindex:indexpath.section] containsobject:[nsstring stringwithformat:@"%ld", (long)indexpath.row]]){ // don't make button because favorite. }else{ // make button because not yet favorite. }
your second table view identical, except near top of "cellforrowatindexpath", similar check:
if([[myfavorites objectatindex:indexpath.section] containsobject:[nsstring stringwithformat:@"%ld", (long)indexpath.row]]){ // favorite, put regular cell stuff here have cell show .... }else{ // not favorite, don't generate cell. cell.visible = no; return cell; }
there other things can require changing setup regular cell custom cell new class , properties blah blah, little more complicated implement, still amount practically same output/processing.
Comments
Post a Comment