Well, after these days of study, my first iOS app, Diary is finished, write a diary below, record the knowledge learned and need to continue to learn the place.
1, first of all viewcontroller, must add two Protocols Uitableviewdatasource and Uitableviewdelegate must implement the two methods of these two protocols,TableView Numberofrowsinsection and TableView Cellforrowatindexpath, the former returns the number of rows the latter sets the line contents.
2, search box, search box need to load protocol uisearchbardelegate, it commonly used two methods -(void) Searchbar: (uisearchbar *) Searchbar Textdidchange: (nsstring *) triggered when searchtext,--text is modified,-(void) searchbarsearchbuttonclicked: ( Uisearchbar *) Searchbar triggered when the search button is clicked.
3, passing values to the next interface.
-(void) Prepareforsegue: (uistoryboardsegue *) Segue sender: (ID) Sender
This method is written in the parent page, such as in the inside write-glyeditviewcontroller *EDITVC = Segue. Destinationviewcontroller;
EDITVC. title = deletdate;
Then the title of your sub-page is equal to Deletdate. No matter which button you click, which page you jump to, the title of your sub-page is equal to Deletdate.
4,// Allow deletion
-(uitableviewcelleditingstyle) TableView: (uitableview *) TableView Editingstyleforrowatindexpath :(nsindexpath *) Indexpath
{
returnuitableviewcelleditingstyledelete;
}
You can return a lot of methods to this method, and then
-(void) TableView: (uitableview *) TableView Commiteditingstyle: (Uitableviewcelleditingstyle ) Editingstyle Forrowatindexpath: (nsindexpath *) indexpath{}
will receive the name of the method you return, such as
if (Editingstyle = = uitableviewcelleditingstyledelete)
{
If delete, do some operation.
}
5, predicate search, mainly used to search strings or arrays, have made notes.
6, set the style of the space, for example
// set width of text box , fillet and color
_contentview. Layer. BorderWidth = 0.2;
_contentview. Layer. Cornerradius = 5.0;
_contentview. Layer. BorderColor = [uicolorgraycolor]. Cgcolor;
General layer. The latter attribute basically can guess the purpose.
7, you define a identifier for a view, and then you want to return to a view.
uistoryboard *storyboard = self. Storyboard;
This identifier is written in the corresponding settings on the storyboard page and must be kept consistent
uiviewcontroller *push = [Storyboard instantiateviewcontrollerwithidentifier: c3>@ "diarylist"];
[self. navigationcontrollerpushviewcontroller:p ush animated:YES];
8, refresh the page.
[Rootcontroller. TableView Reloaddata];
9,
coredata--introduces the framework and completes the operation of module initialization in Appdelegate.
Managedobjectmodel inside, the name of your module should correspond.
Model.xcdatamodeld file describes the structure of the table and the relationship between the table, you see the view is not a table is not a library is not the data, CoreData is covered in the database of a thick layer of steel, so that you can not see anything, you must follow the structure it gives to write a bunch of dead code.
Get Data
glyappdelegate *managed = [[glyappdelegatealloc] init];
nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] initwithentityname: @ "Diarydata"];
Sort
nssortdescriptor *datesort = [[nssortdescriptoralloc] initwithkey :@ "Date"
Ascending:NO];
Fetchrequest. sortdescriptors = @[datesort];
nserror *requesterror = nil;
nsarray *arraydiarydata = [managed. Managedobjectcontext executefetchrequest: fetchrequest
Error:&requesterror];
Get the value
tabledata = [nsmutablearrayarraywithobjects:nil];
Details = [nsmutablearrayarraywithobjects:nil];
for (diarydata *thisdiarydata in Arraydiarydata) {
[tabledata addobject: Thisdiarydata. title];
[details addobject: Thisdiarydata. date];
}
Another example is deleting
glyappdelegate *managed = [[glyappdelegate alloc] init];
nserror *error;
set predicates and search
nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] initwithentityname: @ "Diarydata"];
Fetchrequest. predicate = [nspredicate predicatewithformat:@ "date==%@", deletdate];
nsarray *arrarresult = [managed. Managedobjectcontext executefetchrequest: fetchrequest
error: &error];
if (!error) {
for (diarydata *object in Arrarresult) {
[Managed. Managedobjectcontext DeleteObject: Object];
}
}
if ([Managed. Managedobjectcontext haschanges]) {
[Managed. Managedobjectcontext Save:&error];
}
The new things that become tedious are always not pleasing, this piece needs to continue to learn.
10, automatic layout, 3.5-inch 4-inch screen must be compatible, too soon 5-inch screen to be compatible, the screen needs to be compatible,, this block-there is automatic layout, equity directly does not support or change sotryboard, and so on, generally do not put a large space of the wide high write dead.
Balance: Simple to record is these, may not understand the depth, so this article is not a textbook,,,,, well, clean up the code to start the development of the second app.