objective c - NSURLConnection delegate -
revised...
the crux of app communicating database server. responses server app in xml. there several screens. example, screen 1 lists user's information, screen 2 lists user's past trades, allows new trades, , on.
here code appdelegate:
startviewcontroller *svc = [[startviewcontroller alloc] init]; tradeviewcontroller *tvc = [[tradeviewcontroller alloc] init]; cashviewcontroller *cvc = [[cashviewcontroller alloc] init]; comviewcontroller *covc = [[comviewcontroller alloc] init]; prefsviewcontroller *pvc = [[prefsviewcontroller alloc] init]; nsmutablearray *tabbarviewcontrollers = [[nsmutablearray alloc] initwithcapacity:5]; uitabbarcontroller *tabbarcontroller = [[uitabbarcontroller alloc] init]; uinavigationcontroller *navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:svc]; [tabbarviewcontrollers addobject:navigationcontroller]; navigationcontroller = nil; navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:tvc]; [tabbarviewcontrollers addobject:navigationcontroller]; navigationcontroller = nil; navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:cvc]; [tabbarviewcontrollers addobject:navigationcontroller]; navigationcontroller = nil; navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:covc]; [tabbarviewcontrollers addobject:navigationcontroller]; navigationcontroller = nil; navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:pvc]; [tabbarviewcontrollers addobject:navigationcontroller]; navigationcontroller = nil; [tabbarcontroller setviewcontrollers:tabbarviewcontrollers]; [[self window] setrootviewcontroller:tabbarcontroller]; self.window.backgroundcolor = [uicolor whitecolor]; [self.window makekeyandvisible]; trying stick mvc style, have singleton class of "processing".
now example on how run wall… user can change email address on screen 5. enter new email address text field , click save button. button calls method singleton class sends new email address server , (via url) , receives xml response confirming change.
here problems: 1. start spinner view controller before make singleton class method call - not knowing when app server send/receive finished, how make spinner stop @ right time? can't of singleton class, tried that. know, has within vc or there way change vc output singleton class?
the singleton class nsurlconnection handling of communication. simple, email change way updating transaction tables. seems wrong me , makes difficult keep track on calling what. again, going interpretation of mvc. think easier have nsurlconnection every vc , processing in classes. not mvc(ish).
i have close 100 variables, arrays, etc… in singleton class use assign values vc. seems wrong me can't think of other way.
how can distinguish in nsurlconnection delegate (connectiondidfinishloading) url call being made?
each of delegate methods (such -connectiondidfinishloading:) has connection parameter tells connection sent message. given connection can load 1 url @ time, there's 1 one correspondence between urls , connections.
how can tell outside of "connectiondidfinishloading" when download completed?
that method tells when connection finished. it's store information somewhere it's useful app.
update: based on you've added, "processing" class app's model. rest of app shouldn't care each transaction involves message server -- that's model's business alone. also, there's no reason model has single object (let alone singleton) -- can group of objects work together.
so, might have class (let's call processor) represents application's interface model (some might call "model controller"). instance of processor might create local database storing current local state of app.you might have transaction class represents single transaction server. transaction create request, send server, response, update database, , tell processor transaction done. or, maybe when other part of app (like 1 of view controllers) asks processor process new transaction, processor passes requesting object along transaction creates transaction can update requestor directly.
it's hard best plan app without knowing you're planning on taking it, usual guidelines hold:
break problem parts easier solve
limit scope of each class's responsibilities
if seems complicated, is
breaking model several classes make easier test, well. can imagine how easy write set of unit tests transaction class. same goes processor -- if server transaction stuff in different class, it's easier test processor doing right thing.
Comments
Post a Comment