IOS Mimic TableView Package

Source: Internet
Author: User
Tags sorts

First, affix the non-encapsulated code, so that the comparison with the back

@interface mthomedropdown: UIView

+ (instancetype) dropdown;

@property (nonatomic, strong) Nsarray *categories;

@end

1.categories only one type of data is passed in and cannot be used in multiple places

2. Once encapsulated, it can be used for multiple data passing in multiple places

Two. Encapsulation

@class mthomedropdown;

@protocol Mthomedropdowndatasource <nsobject>

/**

* How many lines are there in the left table?

*/

-(Nsinteger) numberofrowsinmaintable: (mthomedropdown *) homedropdown;

/**

* title of each row in the table on the left

* @param row number

*/

-(nsstring *) Homedropdown: (mthomedropdown *) Homedropdown titleforrowinmaintable: (int) row;

/**

* Sub-data for each row in the table on the left

* @param row number

*/

-(nsarray *) Homedropdown: (mthomedropdown *) Homedropdown subdataforrowinmaintable: (int ) row;

@optional

/**

* icons for each row on the left table

* @param row number

*/

-(nsstring *) Homedropdown: (mthomedropdown *) Homedropdown iconforrowinmaintable: (int) row;

/**

* the selected icon for each row in the table on the left

* @param row number

*/

-(nsstring *) Homedropdown: (mthomedropdown *) Homedropdown selectediconforrowinmaintable: (int ) row;

@end

@interface mthomedropdown: UIView

+ (instancetype) dropdown;

@property (nonatomic, weak) ID<mthomedropdowndatasource> dataSource;

@end

1. Declaration Agreement:<Mthomedropdowndatasource, and the method of declaring the agreement

2. Declare compliance with the data source dataSource of the agreement.

3.. m

/** the line number selected on the left main table * /

@property (nonatomic, assign) nsinteger selectedmainrow;

4. Call the DataSource method to get the data

-(Nsinteger) TableView: (uitableview *) TableView numberofrowsinsection: (nsinteger) section

{

if (TableView = = self . Maintableview) {

return [self. DataSource numberofrowsinmaintable:self];

} Else {

return [self. DataSource homedropdown:self -subdataforrowinmaintable: Self. Selectedmainrow];

}

}

5. Create Mtmetatool Metadata Tool Classes : managing all metadata ( fixed descriptive data )

. h

/**

* return to 344 City

*/

+ (nsarray *) cities;

/**

* return all categorical data

*/

+ (nsarray *) categories;

/**

* return all sort data

*/

+ (nsarray *) sorts;

. m

Static nsarray *_cities;

+ (nsarray *) Cities

{

if (_cities = = Nil) {

_cities = [mtcity objectarraywithfilename:@ "Cities.plist"];;

}

return _cities;

}

Static nsarray *_categories;

+ (nsarray *) Categories

{

if (_categories = = Nil) {

_categories = [mtcategory objectarraywithfilename:@ "Categories.plist"];;

}

return _categories;

}

Static nsarray *_sorts;

+ (nsarray *) sorts

{

if (_sorts = = Nil) {

_sorts = [mtsort objectarraywithfilename:@ "Sorts.plist"];;

}

return _sorts;

}

6. A Zxcategoryviewcontroller class wants to use Homedropdown to display the data, it is necessary to follow the protocol and implement the method

@interface Zxcategoryviewcontroller () <mthomedropdowndatasource>

Dropdown. DataSource = self;

#pragma mark-mthomedropdowndatasource

-(Nsinteger) numberofrowsinmaintable: (mthomedropdown *) homedropdown

{

return [mtmetatool categories]. Count;

}

-(nsstring *) Homedropdown: (mthomedropdown *) Homedropdown titleforrowinmaintable: (int ) Row

{

mtcategory *category = [mtmetatool categories][row];

return category. Name;

}

-(nsstring *) Homedropdown: (mthomedropdown *) Homedropdown iconforrowinmaintable: (int ) Row

{

mtcategory *category = [mtmetatool categories][row];

return category. Small_icon;

}

-(nsstring *) Homedropdown: (mthomedropdown *) Homedropdown selectediconforrowinmaintable: ( int) Row

{

mtcategory *category = [mtmetatool categories][row];

return category. Small_highlighted_icon;

}

-(nsarray *) Homedropdown: (mthomedropdown *) Homedropdown subdataforrowinmaintable: (int ) Row

{

mtcategory *category = [mtmetatool categories][row];

return category. Subcategories;

}

IOS Mimic TableView Package

Related Article

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.