blank window with TTSplitViewController - iphone

I followed the same exact code as the TTCatalog example of TTSplitViewController, starting from the app delegate code, the TTSplitViewController code, and as well as the code for the TTTableViewController. However, when I run the apps I am getting a blank screen.
I started from a window based application and removed the nib file, as the example on TTCatalog doesn't have it.
What am I doing wrong here?
Here's some code, in my app delegate didFinishLaunchedWithOptions I have:
TTNavigator* navigator = [TTNavigator navigator];
navigator.supportsShakeToReload = YES;
navigator.persistenceMode = TTNavigatorPersistenceModeAll;
TTURLMap* map = navigator.URLMap;
[map from:#"*" toViewController:[TTWebController class]];
if (TTIsPad()) {
[map from: #"tt://catalog"
toSharedViewController: [SplitViewController class]];
SplitViewController* controller =
(SplitViewController*)[[TTNavigator navigator] viewControllerForURL:#"tt://catalog"];
TTDASSERT([controller isKindOfClass:[SplitViewController class]]);
map = controller.rightNavigator.URLMap;
}
and everything else is similar to the TTCatalog example.
I was just wondering if anyone can give me a pointer on how to create a TTSplitViewController app, as this is quite frustrating. The example on the TTCatalog seems so simple, but when replicating it, everything fails.
For a full code, can be downloaded here

If you created a project using a xcode template, it means your app delegate is loaded using a nib file. You will have to change it, because Three20 doesn't use nib files at all.
open the main.m file, and change:
int retVal = UIApplicationMain(argc, argv, nil, nil);
to
int retVal = UIApplicationMain(argc, argv, nil, #"AppDelegate");
(Replace #"AppDelegate" with your UIApplicationDelegate class name. That should load your main window into the device.
Also note, that the TTSplitViewController class is a little buggy. I had to modify some code in three20 to make it work as it should. see https://github.com/aporat/three20-splitview-example if you want to try my version of TTSplitViewController.

Related

iPhone zXing QR Scanner - didscanresult function never fires

I have loaded the zXing project into my own project.
It loads fine, the zXing scanner pops up after a button call.
I can dismiss the view controller on thezxingControllerDidCancel but when I scan a QR code, no codes are ever recognised and therefore the didScanResult function never fires.
Does anyone have any idea about this one?
The didScanResult function is below.
-(void)zxingController:(ZXingWidgetController *)controller didScanResult:(NSString *)result{
resultLabel.text = result;
NSLog(#"did scan!!!");
[self dismissModalViewControllerAnimated:NO];
}
Note: I'm not sure if this is relevant, but when the scanner comes up, I get this logged by the app: "wait_fences: failed to receive reply: 10004003"
That tutorial does not mention that you must add a QRCodeReader to the set of readers of your ZXingWidgetController.
ZXingWidgetController has a property called readers, which is an NSSet containing the instances of the readers (e.g. an instance of QRCodeReader). Roughly, the readers' task is to analyze the images your camera takes and to extract the encoded information. Your ZXingWidgetController has to know about the readers it should utilize, otherwise it has no chance to do anything meaningful. So you have to set the readers property before you present the ZXingWidget.
The ZXing project has a sample app which demonstrates this. If you use ARC, then
ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO];
QRCodeReader* qRCodeReader = [[QRCodeReader alloc] init];
NSSet *readers = [[NSSet alloc] initWithObjects:qRCodeReader,nil];
widController.readers = readers;
[self presentModalViewController:widController animated:YES];
should do.

Detect Click on nsurl on uitextview

I have a URL in my textview and when we click on this url it opens this url in default safari. and I want to detect this event. I also tried this
but its not working for me. can any one suggest me how i do this. Provide me a sample for this.
My application deligate is UIResponder type.
the other answer works as expected.
create New File, select Objective-C Class
Class: MyApplication
Subclass of: UIApplication
paste this code in the .m file:
- (BOOL)openURL:(NSURL *)url {
if ([self handleOpenURL:url])
return YES;
else
return [super openURL:url];
}
- (BOOL)handleOpenURL:(NSURL*)url {
NSLog(#"my url handler");
return YES;
}
next open your main.m and change the third parameter
return UIApplicationMain(argc, argv, nil, NSStringFromClass([SampleAppDelegate class]));
to your UIApplication-subclass name
return UIApplicationMain(argc, argv, #"MyApplication", NSStringFromClass([SampleAppDelegate class]));
Take a look at this GitHub project: MSTextView
Assuming you just need to display a static label with links, we have a fairly powerful attributed label in Nimbus that you may wish to check out:
http://docs.nimbuskit.info/group___nimbus_attributed_label.html
The label uses CoreText and NSAttributedString, so it is built on core Apple technologies. It acts in every way like a UILabel. Here's an example of implementing the NIAttributedLabel delegate:
https://github.com/jverkoey/nimbus/blob/master/examples/attributedlabel/BasicAttributedLabel/BasicAttributedLabel/src/MashupViewController.m#L92
More info:
http://nimbuskit.info/

Why is my ScrollView code not displaying?

I have copied some files across from one project to another. The code simply displays a view you can scroll horizontally between items, and then scroll down each item.
The code was in a project with a MainWindow.xib and the relevant name in the plist file.
I'm putting the code into an empty OpenGL ES project which has no nib information in the plist file, and two nib files called "ProjectNameViewController_iPhone.xib" and "ProjectNameViewController_iPad.xib"
When I run the program, none of my code displays. I have a feeling the problem lies with where I am adding subviews to the view controller, and calling this line:
- (id)initWithPageNumber:(int)page
{
if (self = [super initWithNibName:#"MyView" bundle:nil])
{
pageNumber = page;
[self.view addSubview:newsItem];
}
return self;
}
First of all, It's odd to me that the string here is "MyView" and not "MainWindow" as there is nothing in my project called "MyView" (I've searched the project directory and the code is being called)
but getting back to the point, the new code in the open GL ES project is this:
- (id)initWithPageNumber:(int)page
{
if (self = [super initWithNibName:#"IntegrationTestViewController_iPhone" bundle:nil])
{
pageNumber = page;
[self.view addSubview:newsItem];
}
return self;
}
I will put in a check later for Ipad users etc.. If the string is anything else, the code breaks when other parts try to access the classes view which doesn't exist, but with this nothing displays.
what am I not understanding? (I'm quite new to ios / objective-c)
Check the outlets mad to ProjectNameViewController_iPhone.xib and File's owner class.

iPhone SDK NSInternalInconsistencyException

I'm hitting a wall over and over again, trying to solve a problem I've got in xcode. I'm a newbie and started coding just a while ago.
I'm trying to make a XML parser based on this tutorial: http://cocoadevblog.com/iphone-tutorial-creating-a-rss-feed-reader
which works fine separately, but when I'm implementing it into my own project, I get the 'NSInternalInconsistencyException' error, as a result of the following code:
----File: Parser.m----
- (void)parserDidEndDocument:(NSXMLParser *)parser {
if ([_delegate respondsToSelector:#selector(parsedInformation::)]){
[_delegate parsedInformation:information];
}else{
[NSException raise:NSInternalInconsistencyException
format:#"Delegate (%d) doesn't respond to parsedInformation:", _delegate];
}
}
I've tried to remove the if-phrase, and then it calls the correct function, but the data which is supposed to be overhanded, won't get through.
Project setup
The project is a tab-based application. I'm having three classes:
Parser
AlphaTab
RootDelegate
In RootDelegate I used the following code to initialize the tab-view, and then to initialiaze the AlphaTab as a tableView being part of a navigationView:
----RootDelegate.m ----
tabBarController = [[UITabBarController alloc] init];
alphaTab = [[AlphaTab alloc] initWithTabTitle:#"AlphaTab" navigationTitle:#"Exploring"];
UINavigationController *tableNavController = [[[UINavigationController alloc] initWithRootViewController:alphaTab] autorelease];
tableNavController.delegate = self;
[alphaTab release]; // creates your table view's navigation controller, then adds the created view controller. Note I then let go of the view controller as the navigation controller now holds onto it for me. This saves memory.
So good so far.. the problem comes when I use the Parser class, which parses a given XML file. This class is initialized and only implemented in the AlphaTab - therefore it has nothing to do with the RootDelegate class at all. The initialization is done as:
----File AlphaTab.m ----
- (void)loadData{
if(information==nil){
Parser *XMLParser = [[Parser alloc] init];
[XMLParser parseFeed:#"http://frederikbrinck.com/bodil/Example.xml" withDelegate:self];
[XMLParser release];
}else {
[self.tableView reloadData];
}
}
I'm suspecting the parameter withDelegate's value "self" to be the problem, which I think referres to the super class RootDelegate, but I'm not sure. Likewise, I don't know to pass the AlphaTab class' delegate to the function, which I think would solve the problem.
I'm ought to think, that the problem could be created from this line aswell:
----FILE: Parser.h ----
#protocol AlphaTab <UITableViewDelegate>
- (void)parsedInformation:(NSArray *)i;
#end
I've done some research about protocols and respondsToSelector, but honestly, I didn't understand much, since my code is seen from the programmatic perspective of view, without using the InterfaceBuilder at all, since I've been adviced to do that. It hasn't lead to the solution of the problem either.
For further understanding, I then want this function in AlphaTab.m to be called, when the information is parsed.
----FILE AlphaTab.m ----
- (void)parsedInformation:(NSArray *)i {
NSLog(#"The parser has completed parsing");
information = i;
NSLog(#"This is the information: %d", [[information objectAtIndex:0] objectForKey:#"tabTitle"]);
[self.tableView reloadData];
}
I've looked on the net, and I found some explications about the NSInternalInconsistencyException. I've tried to do them as well, for example by setting everybody with themselves as delegates. However, I had no luck. What wonders me most, is that when I use the Parser without having to subclass it's caller (this case: AlphaTab) to a main class, it works like a charm.
I hope you guys can give me a clue. If you need any more information please ask, and I'll be in disposition.
//Brinck10
Please see #warrenm and his comment.

understanding TTNavigator

following situation:
in a TTTableViewController i added some Cells with URLs.
they are opening a class with #"tt://photos" for example. this works quite fine.
the first thing is, i saw some urls in TT Examples like #"tt/photos/1". is it possible to fetch this "1" in my photos class and say, for example okay, please open picture one, ore is this only another URL that was declared in TTNavigatior to open a specific Class?
the other thing is: is it possible to forward an object to the linked class?
clicking a cell opens #"tt://photos" (the linked class in my TTNavigator)
working with normal tableviews i can overwrite my init method and send an object with my initialize method, is this also possible by clicking my TTItems?
thanks!
figured it out myself, for those who need it:
First (passing "subURLs" in your navigator map)
navigating to an URL with #"tt://photos/firstphoto" is possible, you can fetch the "firstphoto" like this:
//Prepare your Navigator Map like this
[map from:#"tt://photos/(initWithNumber:)" toViewController:[PhotoVC class]];
In your PhotoVC you can access this Number:
-(void) initWithNumber: (NSString*)number {
NSLog(#"%#",number);
}
calling your View Controller with this url would look:
PhotoVC* controller = [[PhotoVC alloc] initWithNumber:#"1"];
[navigationController pushViewController:controller animated:YES];
[controller release];
Second (passing objects in an TTTableViewController)
its a bit tricky, but you dont have to Subclass anything.
first, nil the URL in the TableItem
[TTTableLink itemWithText:#"TTTableLink" URL:nil]
in your TTTableViewController write down this method
- (void)didSelectObject:(id)object atIndexPath:(NSIndexPath*)indexPath {
TTURLAction *urlAction = [[[TTURLAction alloc] initWithURLPath:#"tt://photos"] autorelease];
urlAction.query = [NSDictionary dictionaryWithObject:#"firstphoto" forKey:#"photo"];
urlAction.animated = YES;
[[TTNavigator navigator] openURLAction:urlAction];
}
now in your your PhotoVC you need something like this
- (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query {
if (self = [super init]) {
NSLog(#"%#",query);
}
return self;
}
and you are done ;)
I was trying to implement choise's answer, learned a lot, and eventually had to get the callouts showing up and keep the implementation with many urls simple, so here's what i did.
Keep URL in the TableItem,
Use this code in the TTTableViewController subclass.
- (void)didSelectObject:(id)object atIndexPath:(NSIndexPath*)indexPath {
NSLog(#"Its url is %#", [object URL]);
TTURLAction *urlAction = [[[TTURLAction alloc] initWithURLPath:(NSString *)[object URL]] autorelease];
urlAction.query = [NSDictionary dictionaryWithObject:self.user forKey:#"user"];
urlAction.animated = YES;
[[TTNavigator navigator] openURLAction:urlAction];
}
- (BOOL)shouldOpenURL:(NSString*)URL {
return NO;
}
That "shouldOpenURL:" was discovered looking through TTTableViewController, I tried it out, and it worked. Now the table view is not opening a duplicate view, and there are callouts!
Thanks choise!
Although choice's answer works for multiple params when u are creating the TTURLAction in code it is not very useful when u want to embed links to view controllers in your TTStyledLabel.One solution to that is to use multiple params in a single string.
<a href='app://view2/param1=value1&param2=value2&...'>LabelName</a>
if you want the code to parse such urls and get the params please feel free to send me a message and I will send you my parser classes.
(or you can build your own with NSScanner!)
Also dont forget to escape the &s otherwise TTStyledLabel would not like it!
You don't need to run this on current version 1.0.6.2 for TTTableViewController. The "URL" option is working as expected. If it's not working for you, then your URL is broken or your are calling the wrong function on your ViewController. The function you have to call through URL must return an id (be a constructor for a ViewController) of a ViewController. Then it'll work as expected.
I'll changed the example form choise to be like TTNavigator expect it to be.
Add a mapping, which TTNavigator will use to navigate:
//Prepare your Navigator Map like this
[map from:#"tt://photos/(initWithNumber:)" toViewController:[PhotoVC class]];
Create a TTTableLink (or TTStyledText, or other) with an URL set, which should mach your map:
[TTTableLink itemWithText:#"TTTableLink" URL:#"tt://photos/1"]
Add this to your PhotoVC to be called by TTNavigator on the given URL
-(id) initWithNumber: (NSString*)number {
if (self = [super init]) {
self.title = #"Some Title";
NSLog(#"%#",number);
}
return self;
}
You don't need to overwrite the function didSelectObject, as the TTNavigator will call your ViewController through defined constructor function tt://photos/(initWithNumber:)