ios - UICollectionView allow user to choose cell colour -
i making app tracking points, user can add new cell uicollectionview name , default of 0 points.
i don't have issue such not sure on how accomplish task. when user creates new cell want them able choose color of cell 4 predefined options.
if explain me how accomplish make week.
(i tried add images show views give better understanding don't have enough rep)
edit : perhaps should of mentioned first ios project @ work , im super noob, if explain me steps neccessary gets work great.
this method gets called when user creates new cell. (this contained in class sql methods together)
+(void) writedata:(nsstring*)name { [self databaseinit]; if (sqlite3_open(dbpath, &peopledb ) == sqlite_ok) { nsstring *insertsql = [nsstring stringwithformat:@"insert people (name, points) values (\"%@\", \"%i\")",name, 0]; const char *insert_stmt = [insertsql utf8string]; sqlite3_prepare_v2( peopledb, insert_stmt,-1, &statement, null); if (sqlite3_step(statement) == sqlite_done) { nslog(@"added successfully"); } else { nslog(@"%s sqlite_error '%s' (%1d)", __function__, sqlite3_errmsg(peopledb), sqlite3_errcode(peopledb)); } sqlite3_finalize(statement); sqlite3_close(peopledb); } }
then in viewcontroller.m (main view)
- (void)viewdidload { [super viewdidload]; uinib *cellnib = [uinib nibwithnibname:@"custombrowniecell" bundle:nil]; [self.collectionview registernib:cellnib forcellwithreuseidentifier:@"cbcell"]; people2 = [[nsmutablearray alloc] init]; [databaseclass createdb]; people2 = [databaseclass getdata]; }
-(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath{ static nsstring *cellidentifier = @"cbcell"; customcell *cell = (customcell *)[self.collectionview dequeuereusablecellwithreuseidentifier:cellidentifier forindexpath:indexpath]; personobject *a = (personobject*)[people2 objectatindex:indexpath.row]; cell.namelabel.text = a.name; cell.pointslabel.text = [nsstring stringwithformat:@"%i", a.points]; cell.idlabel.text = [nsstring stringwithformat:@"%i", a.id]; return cell; }
you set flag on whatever object (if any) behind cell, , in cellforitematindexpath set background color based on flag.
how give user choice depend on how "add cell" functionality implemented. if show code, more specific or maybe give example.
Comments
Post a Comment