類似于QQ加好友的彈出的小View

首先是一個視圖實現(xiàn)表格方法

<UITableViewDelegate,UITableViewDataSource>


{

//數(shù)組

UITableView *table;

//? ? 表格元素

NSArray *imgarr,*name;

}

這里是初始化

table = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];

//? ? 代理

table.delegate = self;

table.dataSource = self;

//? ? 加載

[self.view addSubview:table];

//? ? 數(shù)組內(nèi)容

imgarr = @[@"1",@"2",@"3"];

name = @[@"確認添加",@"刪除添加",@"關(guān)閉"];

這里是代理方法

//分區(qū)行數(shù)

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return imgarr.count;

}

//內(nèi)容

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@""];

if (!cell) {

cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@""];

}

cell.imageView.image = [UIImage imageNamed:imgarr[indexPath.row]];

cell.textLabel.text = name[indexPath.row];

return cell;

}

//點擊行相應(yīng)事件

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

//? ? 判斷第幾行

if (indexPath.row == 0) {

//? ? ? ? 提示框

UIAlertController*alertController = [UIAlertController alertControllerWithTitle:@"確認添加"message:@"操作以完成" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *action = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:nil];

[alertController addAction:action];

[self presentViewController:alertController animated:YES completion:nil];

}

//如果等于第二行

else if (indexPath.row == 1){

//? ? ? ? 提示框

UIAlertController*alertController = [UIAlertController alertControllerWithTitle:@"刪除添加"message:@"操作以完成" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *action = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:nil];

[alertController addAction:action];

[self presentViewController:alertController animated:YES completion:nil];

}

else if (indexPath.row == 2){

//? ? ? ? 提示框

UIAlertController*alertController = [UIAlertController alertControllerWithTitle:@"關(guān)閉"message:@"操作以完成" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *action = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:nil];

[alertController addAction:action];

[self presentViewController:alertController animated:YES completion:nil];

}

}

調(diào)用在這里實現(xiàn)

//實現(xiàn)按鈕方法

-(void)btnclick{

//初始化內(nèi)容視圖控制器

PopViewController *popview = [[PopViewController alloc]init];

//設(shè)置大小

popview.preferredContentSize = CGSizeMake(150, 140);

// 設(shè)置彈出效果

popview.modalPresentationStyle = UIModalPresentationPopover;

//初始化一個popover

self.pop = popview.popoverPresentationController;

self.pop.delegate = self;

//設(shè)置彈出視圖的顏色

self.pop.backgroundColor = [UIColor whiteColor];

//設(shè)置popover的來源按鈕(以button誰為參照)

self.pop.sourceView = btn;

//設(shè)置彈出視圖的位置(以button誰為參照)

self.pop.sourceRect = btn.bounds;

//箭頭的方向 設(shè)置成UIPopoverArrowDirectionAny 會自動轉(zhuǎn)換方向

self.pop.permittedArrowDirections = UIPopoverArrowDirectionUp;

//模態(tài)出彈框

[self presentViewController:popview animated:YES completion:nil];

}

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{

return UIModalPresentationNone;

}

//點擊蒙版是否消失,默認為yes;

-(BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController{

return YES;

}

//彈框消失時調(diào)用的方法

-(void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController{

NSLog(@"彈框已經(jīng)消失");

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末植影,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子颜价,更是在濱河造成了極大的恐慌,老刑警劉巖诉濒,帶你破解...
    沈念sama閱讀 211,290評論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件拍嵌,死亡現(xiàn)場離奇詭異,居然都是意外死亡循诉,警方通過查閱死者的電腦和手機横辆,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,107評論 2 385
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來茄猫,“玉大人,你說我怎么就攤上這事划纽〈辔辏” “怎么了?”我有些...
    開封第一講書人閱讀 156,872評論 0 347
  • 文/不壞的土叔 我叫張陵靖避,是天一觀的道長潭枣。 經(jīng)常有香客問我,道長幻捏,這世上最難降的妖魔是什么盆犁? 我笑而不...
    開封第一講書人閱讀 56,415評論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮篡九,結(jié)果婚禮上谐岁,老公的妹妹穿的比我還像新娘。我一直安慰自己榛臼,他們只是感情好伊佃,可當我...
    茶點故事閱讀 65,453評論 6 385
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著沛善,像睡著了一般航揉。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上金刁,一...
    開封第一講書人閱讀 49,784評論 1 290
  • 那天帅涂,我揣著相機與錄音,去河邊找鬼胀葱。 笑死,一個胖子當著我的面吹牛笙蒙,可吹牛的內(nèi)容都是我干的抵屿。 我是一名探鬼主播,決...
    沈念sama閱讀 38,927評論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼捅位,長吁一口氣:“原來是場噩夢啊……” “哼轧葛!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起艇搀,我...
    開封第一講書人閱讀 37,691評論 0 266
  • 序言:老撾萬榮一對情侶失蹤尿扯,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后焰雕,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體衷笋,經(jīng)...
    沈念sama閱讀 44,137評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,472評論 2 326
  • 正文 我和宋清朗相戀三年矩屁,在試婚紗的時候發(fā)現(xiàn)自己被綠了辟宗。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,622評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡吝秕,死狀恐怖泊脐,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情烁峭,我是刑警寧澤容客,帶...
    沈念sama閱讀 34,289評論 4 329
  • 正文 年R本政府宣布秕铛,位于F島的核電站,受9級特大地震影響缩挑,放射性物質(zhì)發(fā)生泄漏但两。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,887評論 3 312
  • 文/蒙蒙 一调煎、第九天 我趴在偏房一處隱蔽的房頂上張望镜遣。 院中可真熱鬧,春花似錦士袄、人聲如沸悲关。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,741評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽寓辱。三九已至,卻和暖如春赤拒,著一層夾襖步出監(jiān)牢的瞬間秫筏,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,977評論 1 265
  • 我被黑心中介騙來泰國打工挎挖, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留这敬,地道東北人。 一個月前我還...
    沈念sama閱讀 46,316評論 2 360
  • 正文 我出身青樓蕉朵,卻偏偏與公主長得像崔涂,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子始衅,可洞房花燭夜當晚...
    茶點故事閱讀 43,490評論 2 348

推薦閱讀更多精彩內(nèi)容