• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: iOS - Designing a view controller with multiple views
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: iOS - Designing a view controller with multiple views


  • Subject: Re: iOS - Designing a view controller with multiple views
  • From: email@hidden
  • Date: Mon, 16 Jan 2012 13:02:33 -0600

The request is merely kicked off in viewdidload, but it's asynchronous.

Sent from my iPhone

On Jan 16, 2012, at 12:57 PM, Evadne Wu <email@hidden> wrote:

> Synchronous networking should be avoided, and stealing the view from another view controller is bad.  Methinks.  :p
>
> * Use UINib, create some XIBs whose view outlets connect to different views, but the file’s owner are of the same class
>
> * On initial view load, load the XIB using UINib’s -instantiateWithOwner:options:, which contains a view with an activity indicator, then asynchronously start loading stuff
>
> * When data arrives, look at it then use the same method on UINib to load other views, *then* swizzle your view.  If your view is already presented in a navigation controller, this will likely break everything. I think this might not work out of the box, but you get the idea;
>
>
>    - (void) handleRemoteResponse:(id)response {
>
>        UINavigationController *navController = [[self.navigationController retain] autorelease];
>        NSParameterAssert([self isViewLoaded] && self.view.window && navController.topViewController == self);
>        UIViewController *poppedVC = [[[navController popViewControllerAnimated:NO] retain] autorelease];
>        NSParameterAssert((poppedVC == self) && !self.navigationController);
>
>        UIView *oldView = [[self.view retain] autorelease];
>        NSArray *instantiatedObjects = [[UINib nibWithName:[[self class] nibNameForRemoteResponse:response] bundle:nil] instantiateWithOwner:self options:nil];
>        NSParameterAssert([self isViewLoaded] && ([instantiatedObjects objectAtIndex:0] == self.view) && (oldView != self.view));
>
>        [navController pushViewController:poppedVC animated:NO];
>        NSParameterAssert(navController.topViewController == self);
>
>    }
>
>    + (NSString *) nibNameForRemoteResponse:(id)response {
>
>        NSAssert1(NO, @"%s shall be implemented", __PRETTY_FUNCTION__);
>        return nil;
>
>    }
>
> -ev
>
> On Jan 17, 2012, at 1:38 AM, James West wrote:
>
>> I have a class design issue I was hoping someone could help me out with.
>>
>> I'm currently developing an iOS app that relies heavily on a remote API for all of its data. Most data is requested in viewDidLoad.
>>
>> The availability and format of data can change, and in response to that I need to implement three different designs depending on how much data I have access to: the normal design, a data not found design and a partial data design. I'm trying to declare as much as possible in xib files.
>>
>> Right now I have one 'master' view controller, which when all things go according to plan, presents a view for all of the data. In cases where the data is not available, it instantiates an "inner view" controller and assigns its view to self.view:
>>
>>
>>   if ([analysis length] == 0) {
>>
>>
>>       hasReview = NO;
>>
>>
>>       UnreviewedSPP* unreviewedSPPView = [[UnreviewedSPP alloc] init];
>>
>>
>>       unreviewedSPPView.ProductName = self.productName;
>>
>>
>>       unreviewedSPPView.SdcId = self.sdcId;
>>
>>
>>       unreviewedSPPView.Delegate = self;
>>
>>
>>       NSArray* newViews = [[NSBundle mainBundle] loadNibNamed:@"UnreviewedSPP" owner:unreviewedSPPView options:nil];
>>
>>
>>       self.view = [newViews objectAtIndex:0];
>>
>>
>>       return;
>>
>>
>>   }
>>
>>
>>
>> This works pretty well, except for that fact that I cannot seem to push any new views onto the navigationController stack from the inner view (using a custom button that can execute a block):
>>
>>
>>       [priceButton handleControlEvent:UIControlEventTouchUpInside withBlock:^{
>>
>>
>>           WebViewController* wv = [[[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil] autorelease];
>>
>>
>>           wv.url = offerURL;
>>
>>
>>           [Delegate performSelector:@selector(pushViewControllerFromSubview:) withObject:wv];
>>
>>
>>       }];
>>
>>
>>
>> I've tried using a delegate pattern as well as assigning the outer view controller's navigationcontroller as a property to the inner view. Neither works.
>>
>> This whole thing feels rather hackish, and I'm sure there's something by design in the framework that stops this. Any thoughts?
>>
>> --
>> James West
>> Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >iOS - Designing a view controller with multiple views (From: James West <email@hidden>)
 >Re: iOS - Designing a view controller with multiple views (From: Evadne Wu <email@hidden>)

  • Prev by Date: Re: iOS - Designing a view controller with multiple views
  • Next by Date: Re: Core Data : Correct way to force reading property from sql store?
  • Previous by thread: Re: iOS - Designing a view controller with multiple views
  • Next by thread: iOS: Adding pinch-zoom to UIImageView
  • Index(es):
    • Date
    • Thread