下载地址https://github.com/levey/LeveyPopListView 是arc, 如果是非arc项目要设置一下
方法
选中工程->TARGETS->相应的target然后选中右侧的“Build Phases”,向下就找到“Compile Sources”了。
如何在未使用arc的工程中引入一个使用了arc特性的文件:对相应的文件添加:-fobjc-arc参数
#import <UIKit/UIKit.h>
#import "LeveyPopListView.h" @interface MyViewController : UIViewController<LeveyPopListViewDelegate> @end
#import "MyViewController.h"
@interfaceMyViewController ()
{
UILabel *lb;
}
@property(nonatomic,retain)NSArray *options;
@end
@implementation MyViewController
- (void)viewDidLoad
{
[superviewDidLoad];
self.view.backgroundColor=[UIColorwhiteColor];
//数据源
self.options = [NSArrayarrayWithObjects:
[NSDictionarydictionaryWithObjectsAndKeys:[UIImageimageNamed:@"facebook.png"],@"img",@"Facebook",@"text", nil],
[NSDictionarydictionaryWithObjectsAndKeys:[UIImageimageNamed:@"twitter.png"],@"img",@"Twitter",@"text", nil],
[NSDictionarydictionaryWithObjectsAndKeys:[UIImageimageNamed:@"tumblr.png"],@"img",@"Tumblr",@"text", nil],
[NSDictionarydictionaryWithObjectsAndKeys:[UIImageimageNamed:@"google-plus.png"],@"img",@"Google+",@"text", nil],
[NSDictionarydictionaryWithObjectsAndKeys:[UIImageimageNamed:@"linkedin.png"],@"img",@"LinkedIn",@"text", nil],
[NSDictionarydictionaryWithObjectsAndKeys:[UIImageimageNamed:@"pinterest.png"],@"img",@"Pinterest",@"text", nil],
[NSDictionarydictionaryWithObjectsAndKeys:[UIImageimageNamed:@"dribbble.png"],@"img",@"Dribbble",@"text", nil],
[NSDictionarydictionaryWithObjectsAndKeys:[UIImageimageNamed:@"deviant-art.png"],@"img",@"deviantArt",@"text", nil],
nil];
UIButton *btn=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];
btn.frame=CGRectMake(0, 0, 100, 100);
lb=[[UILabelalloc] initWithFrame:CGRectMake(100, 100, 200,50)];
lb.backgroundColor=[UIColorclearColor];
[lbsetTextColor:[UIColorredColor]];
[self.viewaddSubview:lb];
[lbrelease];
[btn setTitle:@"TEST"forState:UIControlStateNormal];
[btn addTarget:selfaction:@selector(click) forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:btn];
// Do any additional setup after loading the view.
}
-(void)click{
//创建 LeveyPopListView
LeveyPopListView *lv=[[LeveyPopListViewalloc] initWithTitle:@"展示"options:self.options];
lv.delegate=self;
[lv showInView:self.viewanimated:YES];
[lv release];
}
#pragma mark 代理方法
- (void)leveyPopListView:(LeveyPopListView *)popListView didSelectedIndex:(NSInteger)anIndex{
NSLog(@"%zi",anIndex);
NSString *key=[self.options[anIndex] allValues][1];
lb.text=[NSStringstringWithFormat:@"返回数据-->%@",key];
}
- (void)leveyPopListViewDidCancel{
NSLog(@"取消");
}
@end