ios - Objective-C Download PLIST and use within table -


i'm new objective-c programming. i'm trying build app personal use view event info contained on web server. wish each event title string shown separate row within uitableview.

i'm using cfpropertylist create plist mysql. here's plist looks like: enter image description here

i'm downloading plist so:

nsstring *stringurl = @"http://www.example.com/events.plist";         nsurl  *url = [nsurl urlwithstring:stringurl];         nsdata *urldata = [nsdata datawithcontentsofurl:url];         if ( urldata )         {             nsarray       *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);             nsstring  *documentsdirectory = [paths objectatindex:0];              nsstring  *filepath = [nsstring stringwithformat:@"%@/%@", documentsdirectory,@"events.plist"];             [urldata writetofile:filepath atomically:yes];         } 

then how i'm trying load info arrays:

    events = [[nsdictionary alloc] initwithcontentsoffile:filepath];      id = [events objectforkey:@"event id"];     title = [events objectforkey:@"event title"];     date = [events objectforkey:@"event date"];     price = [events objectforkey:@"price"];     totaltickets = [events objectforkey:@"total tickets"];     ticketssold = [events objectforkey:@"tickets sold"];     ticketsremaining = [events objectforkey:@"tickets remaining"];     poststatus = [events objectforkey:@"post status"];     postcontent = [events objectforkey:@"post content"]; 

now here's i'm having trouble. when i'm debugging number of rows 'events' dictionary has returns 0.

therefore cannot set 'numberofrowsinsection'. nor [title objectatindex:indexpath.row] work.

i believe issue lays how i'm setting nsdictionary, due lack of objective-c , array knowledge, i'm unable overcome issue.

here's problem:

events = [[nsdictionary alloc] initwithcontentsoffile:filepath]; 

your plist array of dictionaries , you're trying load array dictionary. try instead:

events = [nsarray arraywithcontentsoffile:filepath]; 

edit: extract titles array can use them in table cells, this:

nsmutablearray *titles = [nsmutablearray array]; (nsdictionary *event in events) {     nsstring *title = [event objectforkey:@"event title"];     [titles addobject:title]; } 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -