Select an item from the drop-down list.

Source: Internet
Author: User

Select an item from the drop-down list.

 

Click the buttons in the menu on the right, and select one from the pop-up list. Respond to the corresponding event and display the text in the menu on the right. The drop-down effect is LMDropdownView, you can use the POD to load the pod 'lmdropdownview'; The LMDropdownView is to assign the desired view to it;

Source code: https://github.com/JxbSir/YiYuanYunGou

The effect is as follows:

 

1: on the home page, define the buttons and bind the view (all attributes, such as btnriview and dropdownView, are not fully written ):

Btnriype = [UIButton buttonWithType: UIButtonTypeCustom]; [btnRigth addTarget: self action: @ selector (btnRightAction) forControlEvents: UIControlEventTouchUpInside]; if (! [OyTool ShardInstance]. bIsForReview) {[self actionCustomNavBtn: btnriw.nrlimage: @ "" htlImage: @ "" title: @ "▽"];} else {[self actionCustomNavBtn: btnriw.nrlimage: @ "" htlImage: @ "" title: [dicTypeName. allValues objectAtIndex: 0];} self. navigationItem. rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: btnriview]; AllProTypeView * tview = [[AllProTypeView alloc] initWithFrame: self. view. bounds]; tview. delegate = self; // in the drop-down list, the effect view dropdownView = [[LMDropdownView alloc] init]; dropdownView. menuBackgroundColor = [UIColor whiteColor]; dropdownView. menuContentView = tview;

 

2: encapsulate the setting buttons:

- (void)actionCustomNavBtn:(UIButton *)btn nrlImage:(NSString *)nrlImage                  htlImage:(NSString *)hltImage                     title:(NSString *)title {    [btn setImage:[UIImage imageNamed:nrlImage] forState:UIControlStateNormal];    if (hltImage) {        [btn setImage:[UIImage imageNamed:hltImage] forState:UIControlStateHighlighted];    } else {        [btn setImage:[UIImage imageNamed:nrlImage] forState:UIControlStateNormal];    }    if (title) {        btn.titleLabel.font = [UIFont boldSystemFontOfSize:13];        [btn setTitle:title forState:UIControlStateNormal];        [btn setTitle:title forState:UIControlStateHighlighted];        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];    }    [btn sizeToFit];}

 

3: btnRightAction ):

- (void)btnRightAction{    if ([dropdownView isOpen])    {        [dropdownView hide];    }    else    {        //[tbViewType reloadData];        [dropdownView showInView:self.view withFrame:CGRectMake(0, 0, mainWidth, self.view.bounds.size.height)];    }}

 

4: The view code of the AllProTypeView drop-down content is as follows (a list ):

. H file content # import <UIKit/UIKit. h> @ protocol AllProTypeViewDelegate-(void) selectedTypeCode :( int) code; @ end @ interface AllProTypeView: UIView @ property (nonatomic, weak) id <AllProTypeViewDelegate> delegate; @ end. m file content @ interface AllProTypeView () <UITableViewDataSource, Region> {UITableView * tbView; NSArray * arrOfType; NSArray * arrOfTypeImage; NSInteger indexType; _ weak id <AllProTypeViewDelegate> de Legate;} @ end @ implementation AllProTypeView @ synthesize delegate;-(id) initWithFrame :( CGRect) frame {self = [super initWithFrame: frame]; if (self) {self. backgroundColor = [UIColor redColor]; tbView = [[UITableView alloc] initWithFrame: CGRectMake (0, 0, mainWidth, frame. size. height) style: UITableViewStyleGrouped]; tbView. delegate = self; tbView. dataSource = self; tbView. backgroundColor = [UIColor white Color]; tbView. separatorStyle = regular; tbView. autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [self addSubview: tbView]; if (! [OyTool ShardInstance]. bIsForReview) {arrOfType = @ [@ "all categories", @ "Mobile Phone digital", @ "computer office", @ "Household Appliances", @ "makeup Personal Protection ", @ "watches and watches", @ "Other Products"]; arrOfTypeImage = @ [@ "sort0", @ "sort100", @ "sort106", @ "sort104 ", @ "sort2", @ "sort222", @ "sort312"];} else {arrOfType = @ [@ "Household Appliances", @ "makeup Care ", @ "watches and watches", @ "Other Products"]; arrOfTypeImage = @ [@ "sort104", @ "sort2", @ "sort222", @ "sort312"];} return self; }# pragma mark-tableview-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {return 1;}-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return arrOfType. count;}-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {return 44;}-(CGFloat) tableView :( UITableView *) tableView heightForHeaderInSection :( NSInteger) section {return 0.1;}-(CGFloat) tableView :( UITableView *) tableView heightForFooterInSection :( NSInteger) section {return 0.1;}-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {// static NSString * CellIdentifier = @ "Cell"; UITableViewCell * cell = nil; // (UITableViewCell *) [tableView progress: CellIdentifier]; if (cell = nil) {cell = [[UITableViewCell alloc] init];} cell. textLabel. text = [NSString stringWithFormat: @ "% @", [arrOfType objectAtIndex: indexPath. row]; NSString * name = [arrOfTypeImage objectAtIndex: indexPath. row]; if (indexPath. row = indexType) {name = [NSString stringWithFormat: @ "% @ _ checked", name]; cell. textLabel. textColor = mainColor; UIImageView * imgOK = [[UIImageView alloc] initWithFrame: CGRectMake (mainWidth-32, 14, 20, 16)]; imgOK. image = [UIImage imageNamed: @ "screening_select"]; [cell addSubview: imgOK];} else {name = [NSString stringWithFormat: @ "% @ _ normal", name];} UIImageView * img = [[UIImageView alloc] initWithFrame: CGRectMake (16, 10, 24, 24)]; img. image = [UIImage imageNamed: name]; [cell addSubview: img]; return cell;}-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {[tableView deselectRowAtIndexPath: indexPath animated: YES]; indexType = indexPath. row; [tbView reloadData]; if (delegate) {NSString * code = [[arrOfTypeImage objectAtIndex: indexPath. row] stringByReplacingOccurrencesOfString: @ "sort" withString: @ ""]; [delegate selectedTypeCode: [code intValue];} @ end

Note: whether the list has been selected or not, and its display effect is different. When triggered, the identifier is assigned a new value, and it is transmitted back to the main view controller through delegate;

 

5: The content in the response to the above delegate in the master controller is:

-(Void) selectedTypeCode :( int) code {iCodeType = code; [dropdownView hide]; NSString * key = [NSString stringWithFormat: @ "% d", code]; NSString * name = [dicTypeName objectForKey: key]; [self actionCustomNavBtn: btnri?nrlimage: @ "" htlImage: @ "0" title: name]; // The content displayed in the rebind list is _ weak typeof (self) wSelf = self; curPage = 1; [self getData: ^ {_ strong typeof (wSelf) sSelf = wSelf; sSelf-> listNew = nil;}];}

 

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.