IOS protocol Use

Source: Internet
Author: User

This whole is a cell, the box of the image (there are a lot of pictures, you can swipe left and right, I do with Icarousel, this agent is written in the custom cell class). Now you need to click on the image to go to the next page .... Now I click on the image, will go into the custom cell class inside the proxy, but the cell class inside, is not let me pop the next viewcontroller. otherwise use[ Self.Navigationcontroller Pushviewcontroller: Showanimated:YES]; this method.


Finally, it is implemented by protocol. When the user clicks on a picture, it goes to the cell classIcarouselProxy method-(void) Carousel: (Icarousel*) Carousel Didselectitematindex: (Nsinteger) IndexHere to pass the index toStarshowviewcontroller,and then in Starshowviewcontroller inside to do push action.

(1) define the agreementImageItemDelegate.h#import<Foundation/Foundation.h>

@protocolImageitemdelegate <NSObject]]]]>

-(void) Passitem: (NSString*) index;//The number of clicks is the firstImageof theIndexPass it over.

@end



(2) inStarShowViewController.hclass to abide by the agreement
#import"ImageItemDelegate.h"
@interfaceStarshowviewcontroller:Uiviewcontroller<uitableviewdelegate,Uitableviewdatasource,imageitemdelegate>{

UITableView*startableview;
Nsmutablearray*stararray;


}



(4) inStarShowTableViewCell.hA proxy is declared inside a class
#import"ImageItemDelegate.h"

@interfaceStarshowtableviewcell:UITableViewCell<Icarouseldatasource,icarouseldelegate,uigesturerecognizerdelegate]]]]>

@property(nonatomic,retain)NSObject<imageitemdelegate> *itemdelegate;//declaring an agent


(5) inSTARSHOWTABLEVIEWCELL.MValue in class

//Select aImage Item
-(void) Carousel: (Icarousel*) Carousel Didselectitematindex: (Nsinteger) index{

NSLog(@ "Index:%ld",(Long) (index);
NSString*str = [NSString stringWithFormat:@ "%ld", index];


UIView*view = Carousel.Currentitemview;

[ Self.itemdelegate Passitem: str];//through the agent toStrUploadStarshowviewcontrollerclass Inside


}


(6) inSTARSHOWVIEWCONTROLLER.MProxy method of the inside table- (UITableViewCell*) TableView: (UITableView*) TableView Cellforrowatindexpath: (Nsindexpath*) IndexpathSet up Proxy
cell.itemdelegate =  Self;//Set up proxy


(7) Enter the next Viewcontroller#pragma mark-imageitemdelegate
//fromCellget the value over there .
-(void) Passitem: (NSString*) index{

Showviewcontroller*show = [[Showviewcontroller Alloc] Init];
Show.Imageidex= index;
[ Self.Navigationcontroller Pushviewcontroller: Showanimated:YES];

}



----------------------
I told you to read a book, and it's not good! There are many ways to do this: ①, you can add click event ② to image directly inside controller, use delegate, implement in current controller to trigger click event ③block Simple ④ event responder chain can handle
The first is not suitable here, the third is not used here, in theory, the block can also pass value, considering the block limit is more, do not use the fourth kind of event responder chain is not very clear what is going on

IOS protocol Use

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.