i having issues getting accomplished correctly. have table view controller parses xml of podcast loaded mp3s. on did select row, have:
the warning connection unused, trying set same way apple documentation has it. have following methods implemented:code:- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { rssentry *entry = [_allentries objectatindex:indexpath.row]; nsurl *url = [nsurl urlwithstring:entry.articleurl]; nslog(@"%@", url); nsurlrequest *therequest = [nsurlrequest requestwithurl:url cachepolicy:nsurlrequestreloadignoringlocalcachedata timeoutinterval:60]; receiveddata = [[nsmutabledata alloc] initwithlength:0]; nsurlconnection *connection = [[nsurlconnection alloc] initwithrequest:therequest delegate:self startimmediately:yes]; }
when click on row, nslog returnscode:- (void) connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response { [uiapplication sharedapplication].networkactivityindicatorvisible = yes; [receiveddata setlength:0]; } - (void) connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data { [receiveddata appenddata:data]; } - (void) connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error { [uiapplication sharedapplication].networkactivityindicatorvisible = no; [connection release]; } - (nscachedurlresponse *) connection:(nsurlconnection *)connection willcacheresponse:(nscachedurlresponse *)cachedresponse { return nil; } - (void) connectiondidfinishloading:(nsurlconnection *)connection { [uiapplication sharedapplication].networkactivityindicatorvisible = no; [connection release]; }
when click row, networkactivityindicator starts spinning, , goes little while , stops. have second table view saved mp3s, files nsmutablearray:code:2012-03-12 12:33:42.154 smcoc[11283:17f03] http://www.smcoc.net/content/audio/sermons/2012/2012_03_11am_the_big_hunt.mp3#!111433318
and rows in table:code:- (void)viewwillappear:(bool)animated { nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectorypath = [paths objectatindex:0]; nsfilemanager *manager = [nsfilemanager defaultmanager]; self.title = @"saved sermons"; self.files = [[manager contentsofdirectoryatpath:documentsdirectorypath error:nil] retain]; self.navigationitem.rightbarbuttonitem = self.editbuttonitem; [self.tableview reloaddata]; [super viewdidload]; [super viewwillappear:animated]; }
however, when go saved table view, nothing appears. doing wrong file not downloading?code:- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { // return number of rows in section. return [self.files count]; } // customize appearance of table view cells. - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease]; } cell.textlabel.text = [self.files objectatindex:indexpath.row]; uifont *cellfont = [uifont fontwithname:@"americantypewriter-bold" size:17]; cell.textlabel.font = cellfont; return cell; }
i believe forgot 1 key piece: when data done downloading, need write device.
add:
to connectiondidfinishloading method.code:[receiveddata writetofile:localfilename atomically:yes];
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