Question

I am presenting a TTWebController as a Modal View using this code:

TTNavigator* navigator = [TTNavigator navigator];
TTURLMap* map = navigator.URLMap;
[map from:@"*" toModalViewController:[TTWebController class]];

Everything works great, except that there is no "close" button on the TTWebController. I know this is usually pushed from the side and given a "back" button, but is there a way to add a "close" button without digging into the actual Three20 code?

Update:

Here is the code that I am using to create the text and then push the Modal View onto the screen. I want to dynamically send whichever URL is clicked, in place of "YourUrlHere".

CGRect frame = CGRectMake(100, 100, 200, 200);
TTStyledTextLabel* label = [[[TTStyledTextLabel alloc] initWithFrame:frame] autorelease];
NSString* labelText = @"http://www.yahoo.com http://www.google.com http://www.test.com";
label.text = [TTStyledText textFromXHTML:labelText lineBreaks:NO URLs:YES];
[self.view addSubview:label];   

TTNavigator* navigator = [TTNavigator navigator];
TTURLMap* map = navigator.URLMap;
myWebView *newViewController = [[myWebView alloc] initWithNibName:@"TTStyledTextLabelWebView" bundle:nil incomingURL:[NSString stringWithString:@"http://www.YourUrlHere.com"]];
[map from:@"*" toModalViewController:[newViewController class]];
Was it helpful?

Solution

Probably what you actually want is your own view controller, that either inherits from or contains a TTWebController. Create and map to that instead of the raw TTWebController, put the button wherever you like and wire up the on touch up inside to [self dismissModalViewControllerAnimated:YES]; That should do the trick.

EDIT:

So now you have a custom web view of type myWebView that I am assuming inherits from TTWebController. That's good. As an aside, you don't really need to initialize a new instance of it just to get the class, you can do that with just [myWebView class] because the class message is on the class, not the instance.

However, even though you have decided to create a new instance using a xib, I don't think TTNavigator will be instantiating your controller instance in that same way. Instead I believe it will launch with this constructor (extracted from TTWebController.m)

- (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query {
  if (self = [self init]) {
    NSURLRequest* request = [query objectForKey:@"request"];
    if (request) {
      [self openRequest:request];
    } else {
      [self openURL:URL];
    }
  }
  return self;
}

So, in your child implementation, you can provide a customized version of this implementation like so:

- (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query {
  if (self = [super initWithNavigatorURL:URL query:query]) {
    // code that creates a button and puts it somewhere
  }
  return self;
}

I haven't tested it, I'd be interested in seeing what it actually is doing if it isn't doing that. If you prefer xibs (like me, unlike three20) then you'll need to do an extra step of loading that. I have a category in my utility framework that helps with this:

NSBundle+LoadNibView.h

#import <Foundation/Foundation.h>

@interface NSBundle(LoadNibView)

+ (id) loadNibView:(NSString*)className;

@end

NSBundle+LoadNibView.m

#import "NSBundle+LoadNibView.h"

@implementation NSBundle(LoadNibView)

+ (id) loadNibView:(NSString*)className
{
    return [[[NSBundle mainBundle] loadNibNamed:className owner:nil options:nil] objectAtIndex:0];
}

@end

The objectAtIndex part is because all xibs contain an array, even if there is only one view inside. This will just return the first UIView in the xib.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top