UIAlertView-Blocks

地址:https://github.com/jivadevoe/UIAlertView-Blocks

HOW TO USE IT

Typically, you'll create items that represent the buttons and the actions to take when they are tapped. For example imagine a dialog box confirming deletion of an item:

RIButtonItem *cancelItem = [RIButtonItem itemWithLabel:@"No" action:^{

// this is the code that will be executed when the user taps "No"

// this is optional... if you leave the action as nil, it won't do anything

// but here, I'm showing a block just to show that you can use one if you want to.

}];

RIButtonItem *deleteItem = [RIButtonItem itemWithLabel:@"Yes" action:^{

// this is the code that will be executed when the user taps "Yes"

// delete the object in question...

[context deleteObject:theObject];

}];

The label property on the button items is the text that will be displayed in the button.

Once you've created these, you simply initialize your UIAlertView using the initializer, passing your button items accordingly:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Delete This Item?"

message:@"Are you sure you want to delete this really important thing?"

cancelButtonItem:cancelItem

otherButtonItems:deleteItem, nil];

[alertView show];

Alternatively you can also use a single line to create buttons and declare the alert view

[[[UIAlertView alloc] initWithTitle:@"Delete This Item?"

message:@"Are you sure you want to delete this really important thing?"

cancelButtonItem:[RIButtonItem itemWithLabel:@"Yes" action:^{

// Handle "Cancel"

}]

otherButtonItems:[RIButtonItem itemWithLabel:@"Delete" action:^{

// Handle "Delete"

}], nil] show];

Again, this is designed to be fire and forget, so you initialize it, show it, and release it. It'll take care of cleaning up after itself.

You can also add a RIButtonItem to the UIAlertView after initialization, just like you normally would:

[alertView addButtonItem:deleteItem];

This is useful if building an UIAlertView, or UIActionSheet dynamically from an Array:

for (RIButtonItem *item in buttonItemArray) {

[alertView addButtonItem:item];

}

That's it!

The UIActionSheet category works virtually the same as the UIAlertView. Just check out the header for the initializer you need to use. It's very straightforward.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末鞠抑,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子钱磅,更是在濱河造成了極大的恐慌铐伴,老刑警劉巖拱雏,帶你破解...
    沈念sama閱讀 216,692評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件忆矛,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡济锄,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,482評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門(mén)霍转,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)荐绝,“玉大人,你說(shuō)我怎么就攤上這事避消〉吞玻” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 162,995評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵沾谓,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我戳鹅,道長(zhǎng)均驶,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,223評(píng)論 1 292
  • 正文 為了忘掉前任枫虏,我火速辦了婚禮妇穴,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘隶债。我一直安慰自己腾它,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,245評(píng)論 6 388
  • 文/花漫 我一把揭開(kāi)白布死讹。 她就那樣靜靜地躺著瞒滴,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上妓忍,一...
    開(kāi)封第一講書(shū)人閱讀 51,208評(píng)論 1 299
  • 那天虏两,我揣著相機(jī)與錄音,去河邊找鬼世剖。 笑死定罢,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的旁瘫。 我是一名探鬼主播祖凫,決...
    沈念sama閱讀 40,091評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼酬凳!你這毒婦竟也來(lái)了惠况?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 38,929評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤粱年,失蹤者是張志新(化名)和其女友劉穎售滤,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體台诗,經(jīng)...
    沈念sama閱讀 45,346評(píng)論 1 311
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡完箩,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,570評(píng)論 2 333
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了拉队。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片弊知。...
    茶點(diǎn)故事閱讀 39,739評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖粱快,靈堂內(nèi)的尸體忽然破棺而出秩彤,到底是詐尸還是另有隱情,我是刑警寧澤事哭,帶...
    沈念sama閱讀 35,437評(píng)論 5 344
  • 正文 年R本政府宣布漫雷,位于F島的核電站,受9級(jí)特大地震影響鳍咱,放射性物質(zhì)發(fā)生泄漏降盹。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,037評(píng)論 3 326
  • 文/蒙蒙 一谤辜、第九天 我趴在偏房一處隱蔽的房頂上張望蓄坏。 院中可真熱鬧,春花似錦丑念、人聲如沸涡戳。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,677評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)渔彰。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間胳岂,已是汗流浹背编整。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,833評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留乳丰,地道東北人掌测。 一個(gè)月前我還...
    沈念sama閱讀 47,760評(píng)論 2 369
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像产园,于是被迫代替她去往敵國(guó)和親汞斧。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,647評(píng)論 2 354

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