Why is my ScrollView code not displaying? - iphone

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.

Related

UIPickerView on Separate Page

I am working on an iPhone app. Initially, I had my pickerview in the same screen so this was just a one page app. After skinning it i realized that i want the pickerview on it's own separate page. So i did that. However, my pickerview originally would update uilabels and other objects on that same page. How can I have my pickerview access those objects from it's new view?
- (IBAction)ShowPickerAction:(id)sender {
if (self.theView == nil) {
theView = [containerView initWithNibName:#"containerView" bundle:nil];
theView.parentView = self;
}
self.theView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:self.theView animated:YES];
}
That is the method I am using to call my new view. But line 3 of the above code gives me the error "No known class name for selector initWithNibName:bundle". I think that error is related to something that i did wrong in my header file. My new class is called containerView. So i did this in my header:
#interface ViewController : UIViewController {
containerView *theView;
But that gives me the error "Unknown type name containerView" even though i do have a class named containerView!!
Look into uiappdelegate protocol or try passing values to through a static function to the previous page.
Use a delegate to pass information back and forth to the view object that instantiatrd the picker view. You want to keep your code coupling as loose as possible, especially if you might like to drop it into your next project. Using a delegate and/or blocks are some of the best ways.

Custom Detail Image View from Three20

I am pretty new with Three20. I have followed ray wenderlich's nice introduction to three20 and the examples within the three20 framework. When I click on a thumbnail in a thumbnail view (subclass of TTThumbsViewController) to launch a Details view, a standard Details image view (deployed by TTPhotoViewController or its super class). I would like to use my own implementation of a Details View instead of the default. I put the following code when I initiated the subclass of TTThumbsViewController and TTThumbsViewControllerDelegate method:
- (id)initWithDelegate:(id<TTThumbsViewControllerDelegate>)delegate {
[super initWithDelegate:delegate];
return self;
}
- (void)thumbsViewController: (TTThumbsViewController*)controller
didSelectPhoto: (id<TTPhoto>)photo {
[navigationController.pushViewController:photoDetailViewController
animated:Yes];
}
But the default TTPhotoViewController view still prevail. When I put a NSLog in the delegate method. I coud see the method was called. I think there is another delegate someone already set in TTThumViewController? Can someone recommend a way to display my detail photo view? Is there another thumbs view controller I can use? Any suggestion will be greatly appreciated.
I'm really new to all of this (coding, etc.) but I'll share what I've found. By looking up the definition of ttthumbsviewcontroller, I was able to find the following method(wrong term?):-
- (void)thumbsTableViewCell:(TTThumbsTableViewCell*)cell didSelectPhoto:(id<TTPhoto>)photo {
[_delegate thumbsViewController:self didSelectPhoto:photo];
BOOL shouldNavigate = YES;
if ([_delegate respondsToSelector:#selector(thumbsViewController:shouldNavigateToPhoto:)]) {
shouldNavigate = [_delegate thumbsViewController:self shouldNavigateToPhoto:photo];
}
if (shouldNavigate) {
NSString* URL = [self URLForPhoto:photo];
if (URL) {
TTOpenURLFromView(URL, self.view);
} else {
TTPhotoViewController* controller = [self createPhotoViewController];
controller.centerPhoto = photo;
[self.navigationController pushViewController:controller animated:YES];
}
}
}
In the else statement, I've found this calls the creation of the photoviewcontroller. By recalling this method (?) in the actual body of my own code and changing the body in the else statement I was able to add a custom detail view. Further down the definition of the ttthumbsnailviewcontroller, you can find that the creatPhotoViewController calls for an initiation of the PhotoViewController so calling that method(?) in the body of the code and initializing another view also works.
If someone can explain whether or not this is a good method of doing this (I have a feeling that is not), it would be appreciated. Also why does putting the method in the body of the code override the call there.

initWith Frame?? CGRectMake - XIB Size is wrong

In my MainControllerClass I have a few XIB's that I am initializing and throwing on the screen - Here is an Example
self.widgetPeopleToBuyFor = [[WidgetAddPeopleToBuyFor alloc] initWithNibName:#"WidgetAddPeopleToBuyFor" bundle:nil andUser:self.currentUser];
self.widgetPeopleToBuyFor.view.frame = CGRectMake(10,10,492,537);
self.widgetPeopleToBuyFor.delegate = self;
[self.viewMainView addSubview:self.widgetPeopleToBuyFor.view];
[self.viewMainView bringSubviewToFront:self.widgetPeopleToBuyFor.view];
if ([self.currentUser.wPeopleToBuyForRect length] > 2) {
NSLog(#"LOADING FROM DB");
CGRect rect9 = CGRectFromString(self.currentUser.wPeopleToBuyForRect);
self.widgetPeopleToBuyFor.view.frame = rect9;
}
else
{
NSLog(#"FIRST TIME");
self.widgetPeopleToBuyFor.view.frame = CGRectMake(10,10,492,537);
}
I'm building this app so the user can resize the the view to their desire, move it around etc. So when he user Exits I call this method to grab the view information.
- (NSString *) showInfoViewSize: (UIView *) view
{
return NSStringFromCGRect(view.frame);
}
So from there I save the information in the Database, it saves ok - But I just learned the size doesn't matter - I could change it to (10,10,200,200) and the view stays the same exact size on the screen.
So I know I threw a buch at you there. But in the End, the DB works fine - the IF statement gets fired off - Its just I can't resize the XIB on launch.
Should I be resizing it a different way? Should I keep track of the TRANSFORM from the pinch recoginier and just retransform it the scaleFactor at load? Seems kinda hokey to me.
Any help is appreciated - I've been beating myself up on this, and I bet its something super simple I'm missing.
view does not loads from xib until it is presented and hence at that time there will be no frame to set for view. let the view load first then set its frame afterwards.
change the view.frame in "viewWillAppear" in your controller's implementation.
Normally when something is just not working, it's because you've got a nil floating around somewhere you didn't expect. Remember, sending messages to nil is completely legal in ObjC (it just always returns nil).
So I'd step through this in the debugger and check everything to make sure it's a real instance and not nil.
But generally what you're doing (allocing a controller with a nib, setting that controller's view's frame, then adding the controller's view to a superview) is the correct way to do it.

“loading” spinner not leaving the TTTableViewController

I had a TTTableViewController used in iPad and initially I want it to be empty. When it first loads it actually calls:
- (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query {
if (self = [super init]) {
self.dataSource = nil;
}
return self;
}
However, the "loading" spinner stays in there and won't go away.
Why is this? I thought that this could happen because init wasn't called, but indeed it is.
I need some help.
When a TTTableViewController is presented on screen, it accesses it's model. If there's no model set, like in your case it creates a model in [TTModelViewController createInterstitialModel]. By default this will be a TTModel (the class not the protocol), which in turn does nothing then appearing to be loading.
In your createModel implementation you would need to create a model that does what you want and assign that to self.model.
Also note, that creating dataSources and / or model in the initializer is not optimal, consider creating your dataSources / models in createModel. They will be created only when needed (when the view appears on screen).

loading custom slider from NIB vs from code: no subviews present when loaded from code

I am trying to create a custom UISlider. I need to insert subviews (like a label) to self. I'm using the
[self insertSubview:_label1 atIndex:2];
method to do so. Everything works fine when I create my slider in IB and assign my PWSlider class to it.
However, if I try to create my PWSlider from code, there are no subviews present when I do my inits (adding my subviews).
For the init in code I override initWithFrame, for the NIB-case I tried both, awakeFromNib as well as initWithCoder - same result.
When I debug with
NSLog(#"subview count: %d", [self.subviews count]);
the result is that loaded from NIB I get 3 subviews, loaded programmatically I get 0.
Any ideas?
I assume your PWSlider is inherited from UISlider and also assume you have code which is something like:
-(id)initWithFrame:(CGRect)r {
self = [super initWithFrame:r];
if(self) {
// add your subviews here, starting from index 0
}
return self;
}
Did you debug and check that your initWithFrame gets called?
Also, if you don't care at which locations your subviews are, use addSubview instead of insertSubview:atIndex:.