Randomly create click object

Source: Internet
Author: User
// Click Event-(void) barbuttonitemclicked {// create data int randomname = arc4random () % 300 + 160000; nsarray * cityarray = @ [@ "Shanghai ", @ "Tianjin", @ "Beijing", @ "Zhengzhou", @ "Guangzhou"]; int randomcity = arc4random () % 5; nsstring * citystr = [cityarray objectatindex: randomcity]; nsdate * Date = [nsdate date]; nsdateformatter * formatter = [[nsdateformatter alloc] init]; [formatter setdateformat: @ "yyyy-mm-dd hh: mm: SS "]; nsstring * time = [formatter stringfromdate: date]; // create object classes * classes = [nsentitydescription insertnewobjectforentityforname: @" classes "inmanagedobjectcontext: Self. managedcontext]; // attribute classes. classessname = [nsstring stringwithformat: @ "BJs % d", randomname]; classes. classesscity = citystr; classes. classesstime = time; classes. classessimage = @ "12.jpg"; [_ managedcontext save: Nil]; [self. dataarray addobject: classes]; [self. tableview reloaddata];}

Delete object
# Pragma mark-set all cells to editable-(bool) tableview :( uitableview *) tableview caneditrowatindexpath :( nsindexpath *) indexpath {return yes;} # pragma mark-edit style-(uitableviewcelleditingstyle) tableview :( uitableview *) tableview editingstyleforrowatindexpath :( nsindexpath *) indexpath {return finished;} # pragma mark-complete and submit-(void) tableview :( uitableview *) tableview commiteditingstyle :( Preview) editingstyle forrowatindexpath :( nsindexpath *) indexpath {If (editingstyle = uitableviewcelleditingstyledelete) {Classes * model = self. dataarray [indexpath. row]; [self. managedcontext deleteobject: Model]; nserror * error = nil; [self. managedcontext save: & error]; If (error = nil) {[self. dataarray removeobject: Model]; [self. tableview deleterowsatindexpaths: @ [indexpath] withrowanimation: uitableviewrowanimationfade] ;}}
 

  






 

Randomly create click object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.