I took source code from a project and tried to implement it into mine. Unfortunately, it didn't work. After analyzing and reanalyzing, I found that the cell swipe only works on the source code file, but does not work on mine.
I copied the .h file into my project:
#import <UIKit/UIKit.h>
#interface DHSwipeAwayCell : UITableViewCell
#property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
#property (weak, nonatomic) IBOutlet UIView *leftView;
#property (weak, nonatomic) IBOutlet UIView *rightView;
#property (weak, nonatomic) IBOutlet UIView *centerView;
#end
and the .m file:
#import "DHSwipeAwayCell.h"
#implementation DHSwipeAwayCell
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect frame = self.bounds;
self.scrollView.frame = frame;
self.scrollView.contentSize = CGSizeMake(frame.size.width*3, frame.size.height);
self.leftView.frame = frame;
self.centerView.frame = CGRectOffset(frame, frame.size.width, 0);
self.rightView.frame = CGRectOffset(frame, frame.size.width*2, 0);
[self.scrollView scrollRectToVisible:self.centerView.frame animated:NO];
}
#end
I even copied the exact same cell into mine, but as soon as it was in my project, it stopped working. I linked the class to the cell. Everything looks completely the same in both view controllers. Maybe I have some settings changed in my project? I'm not sure why I have the same setup in both projects, but only one is working.
It was as simple as unchecking the "Use Autolayout" button!
Related
I am using the storyboard to create a UIView that contains a UIScrollView that has many child items in it. these child items consist of a UIImageView that I am using as a background image for the UIScrollView, a series of UILabels that I populate programmatically, and a series of UITableViews that I populate with data obtained from a called set of library classes. I want all of this in my UIScrollView so the User can scroll through all of the information without having multiple views being displayed. I have browsed through a lot of postings here and have used a lot of the suggestions, but have been unable to successfully have the view scroll and allow the user to see all the data I'm attempting to present.
Here's a screen shot of the Storyboard followed by a shot of the attribute inspector for my UIScrollView
I'll also provide the .h and .m files
weatherController.h
#import <UIKit/UIKit.h>
#import "WeatherParser.h"
#import "WeatherLocation.h"
#import "WeatherImg.h"
#import "WeatherWind.h"
#import "ForcastDay.h"
#import "ForecastItem.h"
#import "Condition.h"
#import "Atmo.h"
#import "Astro.h"
#class WeatherParser;
#class WeatherParserDelegate;
#class WeatherLocation;
#class WeatherImg;
#class WeatherWind;
#class ForcastDay;
#class ForecastItem;
#class Condition;
#class Atmo;
#class Astro;
#interface weatherController : UIViewController <UITableViewDataSource,UITableViewDelegate,WeatherParserDelegate>{
WeatherParser * _rssParser;
bool loadingEvents;
}
#property (nonatomic, retain) WeatherParser * rssParser;
#property bool loadingEvents;
#property (retain, nonatomic) IBOutlet UIScrollView *scrollView;
#property (weak, nonatomic) IBOutlet UILabel *cityLabel;
#property (weak, nonatomic) IBOutlet UILabel *state_countryLabel;
#property (weak, nonatomic) IBOutlet UILabel *currHighLabel;
#property (weak, nonatomic) IBOutlet UILabel *currLowLabel;
#property (weak, nonatomic) IBOutlet UILabel *currTempLabel;
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#property (weak, nonatomic) IBOutlet UIImageView *logoImageView;
#property (weak, nonatomic) IBOutlet UILabel *logoLabel;
#property (weak, nonatomic) IBOutlet UITableView *forecastTableView;
#property (weak, nonatomic) IBOutlet UITableView *atmoTableView;
#property (weak, nonatomic) IBOutlet UITableView *windTableView;
#property (weak, nonatomic) IBOutlet UITableView *astroTableView;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
#property (nonatomic, retain) NSMutableArray *forecastDays;
#property bool logoSet;
#end
and here's my weatherController.m file. I'm going to only add the viewDidLoad method which is the only method containing code regarding my UIScrollView.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_scrollView.delegate = self;
// self.scrollView.frame = CGRectMake(0, 0, 320.0f, 480.0f);
self.scrollView.contentSize =CGSizeMake(320.0F, 480.0F); //(320, 1210)];
[_scrollView setScrollEnabled:YES];
}
I would appreciate any help regarding what it is I'm either doing wrong or missing. If I set up my frame and contentSize to the following:
self.scrollView.frame = CGRectMake(0, 0, 320.0f, 480.0f);
self.scrollView.contentSize =CGSizeMake(320.0F, 1210.0F);
I do get the UIScrollView to scroll, but the image for the background is only the size of the frame, and none of the rest of the child content on the UIScrollView is displayed. It seems like it's allowing me to scroll but I'm only able to view the content that is viewable within the frame.
Again, thank you in advance for any help offered.
As the comments are suggesting, it's generally a bad idea to put a UITableView within a UIScrollView. I won't be too hard on you though, because there is a time and place where it is an acceptable solution. I'll let you judge if this time is now or not.
For reasons I still don't fully understand, UIScrollView behaves more like you expect it to if you enclose the entire contents in a single UIView that is as big as you want the UIScrollView to scroll.
I'm developing an iOS 5+ application with latest SDK and I have a custom UIView with a custom XIB.
This is TopMenuView.h:
#import <UIKit/UIKit.h>
#interface TopMenuView : UIView
#property (weak, nonatomic) IBOutlet UIButton *MenuButton;
#property (weak, nonatomic) IBOutlet UILabel *MenuLabel;
#property (weak, nonatomic) IBOutlet UIButton *SearchButton;
#property (weak, nonatomic) IBOutlet UIButton *ProfileButton;
#property (weak, nonatomic) IBOutlet UIButton *HomeButton;
#property (weak, nonatomic) UIViewController* parentController;
- (IBAction)MenuClicked:(id)sender;
- (IBAction)SearchClicked:(id)sender;
- (IBAction)ProfileClicked:(id)sender;
- (IBAction)HomeClicked:(id)sender;
+ (id)topMenuView;
#end
This is TopMenuView.m:
#import "TopMenuView.h"
#import "SearchViewController.h"
#import "ProfileViewController.h"
#import "HomeViewController.h"
#import "SWRevealViewController.h"
#implementation TopMenuView
#synthesize parentController;
+ (id)topMenuView
{
TopMenuView* topView = [[[NSBundle mainBundle] loadNibNamed:#"TopMenuView"
owner:nil
options:nil] lastObject];
// make sure customView is not nil or the wrong class!
if ([topView isKindOfClass:[TopMenuView class]])
{
[topView setFrame:CGRectMake(0, 0, 320, 49)];
return topView;
}
else
return nil;
}
#pragma mark -
#pragma mark IBAction methods
- (IBAction)MenuClicked:(id)sender
{
[self.parentController.revealViewController revealToggle:sender];
}
- (IBAction)SearchClicked:(id)sender
{
SearchViewController* search =
[[SearchViewController alloc] initWithNibName:#"SearchViewController"
bundle:nil];
[self.parentController.revealViewController setFrontViewController:search];
}
- (IBAction)ProfileClicked:(id)sender
{
ProfileViewController* profile =
[[ProfileViewController alloc] initWithNibName:#"MyProfileViewController"
bundle:nil];
[self.parentController.revealViewController setFrontViewController:profile];
}
- (IBAction)HomeClicked:(id)sender
{
HomeViewController* home =
[[HomeViewController alloc] initWithNibName:#"HomeViewController"
bundle:nil];
[self.parentController.revealViewController setFrontViewController:home];
}
#end
And on UIViewController I do this to show it:
- (void)viewDidLoad
{
[super viewDidLoad];
topMenuView = [TopMenuView topMenuView];
topMenuView.MenuLabel.text = #"Home";
topMenuView.parentController = self;
[self.view addSubview:topMenuView];
// Set the gesture to open the slide menu.
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
And this is the view:
This code works perfectly only on iPhone Retina 4-inch simulator. On iPhone Retina 3.5-inch and on iPhone simulator, it doesn't work.
The problem is that I do a click over any of that "buttons" it do nothing. No Touch Inside Up event is throw (I set a debug point inside the IBAction method).
I haven't test it on a real iPhone because I don't have a developer license yet.
What's happening? Why it doesn't work on iPhone 3.5-inch?
You probably have another view which covers over your buttons. Check your xib file for a view that is possibly being expanded by the system when it has a different size screen.
I had the same problem. Everything worked fine, until I uncheck "Use AutoLayout" button in Storyboard. I have UIView with button placed on it. And have action related to this button. Then in iPhone Retina 3.5-inch Simulator it doesn't respond to that action.
Finally, I found the solution in the Storyboard. It sets the height of my view where button is placed to 0. I don't know why. So I just specify its height programmatically.
Hope this will help!
I'm creating a universal application in iOS 4.2 and above.
I have a nib called DataInputViewController_iPhone.xib. On the first view controller which comes up I have a button which should launch the class DataInputViewController. It does it, but it doesn't show the contents of the XIB file. It just shows a black screen.
Any ideas why this happens?
I have this code which calls the new view controller:
-(IBAction)clickedButton:(id)sender {
if((UIButton *)sender == (UIButton *)startButton){
NSString *nibName;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
nibName = #"DataInputViewController_iPhone";
} else {
nibName = #"DataInputViewController_iPad";
}
DataInputViewController *nextVC = [[DataInputViewController alloc] initWithNibName:nibName bundle:nil];
[self.navigationController pushViewController:nextVC animated:YES];
}
else if((UIButton *)sender == (UIButton *)otherButton){
NSLog(#"clicked the other button");
}
}
NSLogging in this method and in the init method of the new view controller tells me that the nibNameOrNil variable is pulled through correctly.
This is what the (standard) init method looks like in DataInputViewController.m:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
Any ideas why this is happening? Or how to fix?
Thanks :)
You don't have to manually set up the nib name. Just name them DataInputViewController~iphone.xib and DataInputViewController~ipad.xib, then call [[DataInputViewController alloc] init].
See iOS Supports Device-Specific Resources for more information.
I had the same problem. Just clean your project, close XCode, reboot your Mac and open project again.
And don't forget delete app on simulator or device previously.
The only way I have found to fix this is to delete the nibs and class and then recreate them. Not particularly elegant, but it works ...
I had this same issue where I needed to load either iPad or iPhone .xib files for a utility view controller. It is a form so it had a lot of UILabel and UITextField elements that were linked as IBOutlets. I would construct the entire layout, link all of the elements, and it worked fine until when I built and ran it. I even took the advice posted on this thread and re-created both .xib's and the class files (a great deal of linking IBOutlets) with no success.
The problem was this. The root view cannot be #synthesized in the implementation of the class. As soon as I synthesized the base view, everything went black. By simply removing the "#synthesize view;" line, everything worked like a charm. When I presented my view controller everything was there again.
Here is the header file for the class with all of the IBOutlets:
#import <UIKit/UIKit.h>
#interface SignUpFormViewController : UIViewController <UITextFieldDelegate, NSXMLParserDelegate>
#property (strong, nonatomic) IBOutlet UIView *rootView;
#property (weak, nonatomic) IBOutlet UILabel *signUpFormLabel;
#property (weak, nonatomic) IBOutlet UIButton *infoButton;
#property (weak, nonatomic) IBOutlet UILabel *enterEmailLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterEmailTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterPasswordLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterPasswordTextField;
#property (weak, nonatomic) IBOutlet UILabel *reEnterPasswordLabel;
#property (weak, nonatomic) IBOutlet UITextField *reEnterPasswordTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterFirstNameLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterFirstNameTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterLastNameLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterLastNameTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterPhoneNumberLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterPhoneNumberTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterStreetAddressLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterStreetAddressTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterStreetAddress2Label;
#property (weak, nonatomic) IBOutlet UITextField *enterStreetAddress2TextField;
#property (weak, nonatomic) IBOutlet UILabel *enterCityLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterCityTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterStateLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterStateTextField;
#property (weak, nonatomic) IBOutlet UILabel *enterZipLabel;
#property (weak, nonatomic) IBOutlet UITextField *enterZipTextField;
#property (weak, nonatomic) IBOutlet UIButton *backButton;
#property (weak, nonatomic) IBOutlet UIButton *signUpNowButton;
- (IBAction)infoButtonPressed:(id)sender;
- (IBAction)backButtonPressed:(id)sender;
- (IBAction)signUpNowButtonPressed:(id)sender;
#end
Here is the implementation file with the root view being synthesized:
#import "SignUpFormViewController.h"
#implementation SignUpFormViewController
#synthesize rootView,signUpFormLabel,infoButton,enterEmailLabel,enterEmailTextField,enterPasswordLabel,enterPasswordTextField,reEnterPasswordLabel,reEnterPasswordTextField,enterFirstNameLabel,enterFirstNameTextField,enterLastNameLabel,enterLastNameTextField,enterPhoneNumberLabel,enterPhoneNumberTextField,enterStreetAddressLabel,enterStreetAddressTextField,enterStreetAddress2Label,enterStreetAddress2TextField,enterCityLabel,enterCityTextField,enterStateLabel,enterStateTextField,enterZipLabel,enterZipTextField,backButton,signUpNowButton,btnDone,btnPrev,btnNext,inputAccView,activeTextField,currentString;
Simply remove the "rootView" from the list of properties being synthesized and this should fix the problem. Much easier than deleting the .xib files for BOTH iPad and iPhone layouts and re-creating them.
FYI I am using xCode 4.6.3 with target SDK = 6.1
I hope this helps anybody else that experiences this time-consuming and very frustrating issue.
This may help you: delete your app on the simulator or device and run again. I find if I twiddle with nibs too much, especially around names or localization, it appears that everything works (I get no errors), but Xcode is actually ignoring the changes.
So perform a Clean (Product->Clean), delete from simulator or device, run again.
You have to make sure to implement the loadView method in your DataInputViewController.m and inside the method add the line [super loadView], like this:
- (void)loadView {
[super loadView];
}
I have found that not dragging an outlet from the File Owner to your custom sub-classed UITableViewCell.h or .m file can cause the blackness as well. Make sure that you drag an outlet to one of the two files associated with your sub-class of UITableViewCell.
In my case,
I was receive xib file from co-worker.
well loaded xib but did not shown.
spent all my one a day because Hidden checkbox was checked
check Hidden checkbox in xib.
Simple Fix!!
Navigating to version editor and back to standard editor fixed the problem for me
I'm diving into iPad development and I'm still learning how everything works together. I understand how to add standard view (i.e. buttons, tableviews, datepicker, etc.) to my UI using both Xcode and Interface Builder, but now I'm trying to add a custom calendar control (TapkuLibrary) to the left window in my UISplitView application which doesn't involve Interface Builder, right? So if I have a custom view (in this case, the TKCalendarMonthView), how do I programmatically add it to one of the views in my UI (in this case, the RootViewController)? Below are some relevant code snippets from my project...
RootViewController interface
#interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate> {
DetailViewController *detailViewController;
NSFetchedResultsController *fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
}
#property (nonatomic, retain) IBOutlet DetailViewController *detailViewController;
#property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
#property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
- (void)insertNewObject:(id)sender;
TKCalendarMonthView interface
#class TKMonthGridView,TKCalendarDayView;
#protocol TKCalendarMonthViewDelegate, TKCalendarMonthViewDataSource;
#interface TKCalendarMonthView : UIView {
id <TKCalendarMonthViewDelegate> delegate;
id <TKCalendarMonthViewDataSource> dataSource;
NSDate *currentMonth;
NSDate *selectedMonth;
NSMutableArray *deck;
UIButton *left;
NSString *monthYear;
UIButton *right;
UIImageView *shadow;
UIScrollView *scrollView;
}
#property (readonly,nonatomic) NSString *monthYear;
#property (readonly,nonatomic) NSDate *monthDate;
#property (assign,nonatomic) id <TKCalendarMonthViewDataSource> dataSource;
#property (assign,nonatomic) id <TKCalendarMonthViewDelegate> delegate;
- (id) init;
- (void) reload;
- (void) selectDate:(NSDate *)date;
Thanks in advance for all your help! I still have a ton to learn, so I apologize if the question is absurd in any way. I'm going to continue researching this question right now!
Assuming you have initialized the custom UIView, you need to add it as a subview of the viewController's view.
- (void)addSubview:(UIView *)view
So an example would be if you have a plain viewController called myVC, which has simply a blank white UIView as its view, you would say this:
CGRect customViewsFrame = CGRectMake(10, 30, 5, 2);
MyCustomView *myView = [[MyCustomView alloc] initWithFrame:customViewsFrame];
[[myVC view] addSubview:myView];
[myView release]; //Since you called "alloc" on this, you have to release it too
Then it will show up in the viewController's view, taking up the space indicated by the CGRect.
The CGRect's coordinates specify a location in the local coordinate system of the superview you are adding to, if I'm not mistaken.
CGRect CGRectMake (CGFloat x, CGFloat y, CGFloat width, CGFloat height);
I'm not booted into Mac OS X so I can't verify this completely, but this is your general pattern:
RootViewController.h:
...
#interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate>
{
...
TKCalendarMonthView* calendarView;
...
}
...
#property (nonatomic, retain) TKCalendarMonthView* calendarView;
...
RootViewController.m:
...
#synthesize calendarView;
...
- (void)dealloc
{
...
[calendarView release];
...
}
...
- (void)viewDidLoad
{
...
TKCalendarMonthView* aCalendarView = [[TKCalendarMonthView alloc] init]; // <-- possibly initWithFrame here
self.calendarView = aCalendarView;
[aCalendarView release];
[self addSubview:self.calendarView];
...
}
I am trying to load a UIView with multiple data. The problem is data is not displays in first load but loads it in subsequent clicks. Can you help me trace the problem.
FirstViewController.h
#import <UIKit/UIKit.h>
#class SecondViewController;
#interface FirstViewController : UIViewController {
IBOutlet SecondViewController *mySecondViewController;
IBOutlet UIImageView *myimage1;
IBOutlet UIImageView *myimage2;
IBOutlet UILabel *mylabel1;
IBOutlet UILabel *mylabel2;
}
#property (nonatomic, retain) IBOutlet SecondViewController *mySecondViewController;
#property (nonatomic, retain) IBOutlet UIImageView *myimage1;
#property (nonatomic, retain) IBOutlet UIImageView *myimage2;
#property (nonatomic, retain) IBOutlet UILabel *mylabel1;
#property (nonatomic, retain) IBOutlet UILabel *mylabel2;
- (IBAction)bringNextView:(id)sender;
- (IBAction)bringNextView2: (id)sender;
#end
FirstViewController.m
#import "FirstViewController.h"
#import "SecondViewController.h"
#implementation FirstViewController
#synthesize mySecondViewController,myimage1, myimage2, mylabel1, mylabel2;
- (IBAction)bringNextView:(id)sender {
mySecondViewController.name.text = #"Paul";
mySecondViewController.myimageview.image = [UIImage imageNamed:#"Paul.png"];
mySecondViewController.statmsg.text = #"Doing iPhone Development";
[[self navigationController] pushViewController:mySecondViewController animated:YES];
}
SecondViewController.m
#import "SecondViewController.h"
#implementation SecondViewController
#synthesize myimageview, name, statmsg
- (void)viewDidLoad {
[self setTitle:#"Details"];
[super viewDidLoad];
}
Properties are not coming for the first time. But are displays after returning from view and then loading view again.
I am loading SecondViewController from FirstViewController.
Hi I have solved this. Actually I was pushing my view controller after setting up the property and that caused this issue.
Instead of :
mySecondViewController.name.text = #"Paul";
mySecondViewController.myimageview.image = [UIImage imageNamed:#"Paul.png"];
mySecondViewController.statmsg.text = #"Doing iPhone Development";
[[self navigationController] pushViewController:mySecondViewController animated:YES];
It should be :
[[self navigationController] pushViewController:mySecondViewController animated:YES];
mySecondViewController.name.text = #"Paul";
mySecondViewController.myimageview.image = [UIImage imageNamed:#"Paul.png"];
mySecondViewController.statmsg.text = #"Doing iPhone Development";