i using this bit of blueprint setting block based action sheet. actions action sheet cancel, download, , stream. changed blockbasedactionsheet.h to:
and blockbasedactionsheet.m to:code:@interface blockbasedactionsheet : uiactionsheet<uiactionsheetdelegate> { } @property (copy) void (^cancelblock)(); @property (copy) void (^downloadblock)(); @property (copy) void (^streamblock)(); - (id)initwithtitle:(nsstring *)title cancelbuttontitle:(nsstring *)cancelbuttontitle downloadbuttontitle:(nsstring *)downloadbuttontitle streambuttontitle:(nsstring *)streambuttontitle cancelaction:(void (^)())cancelblock downloadaction:(void (^)())downloadblock streamaction:(void (^)())streamblock; @end
in tableview didselectrowatindexpath, put following:code:@implementation blockbasedactionsheet @synthesize cancelblock = _cancelblock, streamblock = _streamblock, downloadblock = _downloadblock; - (id)initwithtitle:(nsstring *)title cancelbuttontitle:(nsstring *)cancelbuttontitle downloadbuttontitle:(nsstring *)downloadbuttontitle streambuttontitle:(nsstring *)streambuttontitle cancelaction:(void (^)())cancelblock downloadaction:(void (^)())downloadblock streamaction:(void (^)())streamblock { self = [super initwithtitle:title delegate:self cancelbuttontitle:cancelbuttontitle destructivebuttontitle:nil otherbuttontitles:downloadbuttontitle, streambuttontitle, nil]; if (self) { _cancelblock = block_copy(cancelblock); _downloadblock = block_copy(downloadblock); _streamblock = block_copy(streamblock); } return self; } -(void)actionsheet:(uiactionsheet *)actionsheet clickedbuttonatindex:(nsinteger)buttonindex { nsassert(actionsheet == self, @"wrong action sheet passed"); if (buttonindex == 0) { if (self.cancelblock) { self.cancelblock(); } } if (buttonindex == 1) { if (self.downloadblock) { self.downloadblock(); } } if (buttonindex == 2) { if (self.streamblock) { self.streamblock(); } } } @end
the action sheet presents top bottom:code:blockbasedactionsheet *asksheet = [[blockbasedactionsheet alloc] initwithtitle:@"what want do" cancelbuttontitle:@"cancel" downloadbuttontitle:@"download" streambuttontitle:@"stream" cancelaction:^ { }downloadaction:^ { uitableviewcell *cell = [tableview cellforrowatindexpath:indexpath]; cgrect frame = cgrectmake(0, 49, 160, 50); progress = [[uiprogressview alloc] initwithframe:frame]; cell.contentview.tag = 100; [cell.contentview addsubview:progress]; rssentry *entry = [_allentries objectatindex:indexpath.row]; nsurl *url = [nsurl urlwithstring:entry.articleurl]; self.nameit = entry.articletitle; nsurlrequest *therequest = [nsurlrequest requestwithurl:url cachepolicy:nsurlrequestreloadignoringlocalcachedata timeoutinterval:60]; receiveddata = [[nsmutabledata alloc] initwithlength:0]; nsurlconnection *connection = [[nsurlconnection alloc] initwithrequest:therequest delegate:self startimmediately:yes]; }streamaction:^ { if (_webviewcontroller == nil) { self.webviewcontroller = [[[webviewcontroller alloc] initwithnibname:@"webviewcontroller" bundle:[nsbundle mainbundle]] autorelease]; } rssentry *entry = [_allentries objectatindex:indexpath.row]; _webviewcontroller.entry = entry; [self.navigationcontroller pushviewcontroller:_webviewcontroller animated:yes]; }]; [asksheet showinview:self.tabbarcontroller.view]; [asksheet release];
download
stream
cancel
when press download, cancel action performs
stream, download action performs
cancel, stream action performs
solution:
in .m of blockbasedactionsheet, changed to:
code:if (buttonindex == [self cancelbuttonindex]) { if (self.cancelblock) { self.cancelblock(); } } if (buttonindex == [self firstotherbuttonindex]) { if (self.downloadblock) { self.downloadblock(); } } if (buttonindex == [self firstotherbuttonindex] +1) { if (self.streamblock) { self.streamblock(); } }
edit post , mark resolved if don't have question anymore...
(edit > advanced > 1 of menus lets mark resolved.)
Forums iPhone, iPad, and iPod Touch iOS Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
No comments:
Post a Comment