How can I subclass UITextView in UIActionSheet to overwrite canBeforeFirstResponder to disable copy, select, and select all in UITextView.
#import <UIKit/UIKit.h>
#class English;
#protocol EnglishDelegate
- (void)dismissViewDidFinish:(UIViewController *)viewController;
#end
#interface English: UIViewController <UITextViewDelegate, UIScrollViewDelegate>
{
id<EnglishDelegate> delegate;
UITextView *textView;
UINavigationBar *navBar;
UINavigationController *navigationController;
}
#property (nonatomic, retain) UITextView *textView;
#property (nonatomic, assign) UINavigationBar *navBar;
#property (strong, nonatomic) UINavigationController *navigationController;
#property (nonatomic, assign) id<EnglishDelegate> delegate;
#property (nonatomic, retain) UIScrollView *scrollView;
-(void)dismissView:(id)sender;
#end
Anyone knows how to subclass it in h file.
Thanks for help.
You wouldn't subclass UITextView inside of another class; you would just plain subclass it in another file and override the canBecomeFirstResponder as so:
- (BOOL)canBecomeFirstResponder {
return NO;
}
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
So we have recently started developing applications for the iPad for our company. Unfortunately none of us here have ever done any iPhone/iPad development so we are just kind of learning on the fly and winging it. Basically our problem is happening when we try to push a view onto the screen when a table row is clicked. Neither of us can figure out why it's not doing it because the code looks 100% correct by anything we can tell. Here is what the didRowSelectedAtIndex: method looks like:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic -- create and push a new view controller
if(pdvController == nil)
pdvController = [[PersonDetailViewController alloc] initWithNibName:#"PersonDetailView" bundle:[NSBundle mainBundle]];
Person *aPerson = [appDelegate.people objectAtIndex:indexPath.row];
pdvController.aPerson = aPerson;
[self.appDelegate.navigationController pushViewController:pdvController animated:YES];
}
and here is the header for the toolbarSearchViewController:
#import <UIKit/UIKit.h>
#import "RecentSearchesController.h"
#import "PersonDetailViewController.h"
#class ToolbarSearchAppDelegate, PersonDetailViewController;
#interface ToolbarSearchViewController : UIViewController <UISearchBarDelegate, UIPopoverControllerDelegate, RecentSearchesDelegate> {
ToolbarSearchAppDelegate *appDelegate;
UIToolbar *toolbar;
UISearchBar *searchBar;
UITableView *resultsTable;
PersonDetailViewController *pdvController;
RecentSearchesController *recentSearchesController;
UITableViewController *resultsTableController;
UIPopoverController *recentSearchesPopoverController;
}
#property (nonatomic, retain) IBOutlet UIToolbar *toolbar;
#property (nonatomic, retain) UISearchBar *searchBar;
#property (nonatomic, retain) IBOutlet UITableView *resultsTable;
#property (nonatomic, retain) ToolbarSearchAppDelegate *appDelegate;
#property (nonatomic, retain) PersonDetailViewController *pdvController;
#property (nonatomic, retain) UITableViewController *resultsTableController;
#property (nonatomic, retain) RecentSearchesController *recentSearchesController;
#property (nonatomic, retain) UIPopoverController *recentSearchesPopoverController;
#end
and the ToolbarSearchAppDelegate header:
#import <UIKit/UIKit.h>
#class ToolbarSearchViewController;
#interface ToolbarSearchAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
ToolbarSearchViewController *viewController;
UINavigationController *navigationController;
NSMutableArray *people;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet ToolbarSearchViewController *viewController;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#property (nonatomic, retain) NSMutableArray *people;
#end
and finally the personDetailController.h:
#import <UIKit/UIKit.h>
#class Person;
#interface PersonDetailViewController : UIViewController {
IBOutlet UITableView *tableView;
Person *aPerson;
}
#property (nonatomic, retain) Person *aPerson;
#property (nonatomic, retain) UITableView *tableView;
#end
We are getting pretty annoyed because neither of us can figure out why it's not loading and any help or insight you guys could provide would be amazing. I wasn't sure what you may need to see, so if you need anything more specific, let me know and I will post it. Thanks!
ps. I am not sure how the code tags are going to handle all of Obj-c's quirky syntax, so if you see syntax errors, just ignore them. Assume that it is syntactically correct and will compile and run...
This line looks a little odd:
[self.appDelegate.navigationController pushViewController:pdvController animated:YES];
try and make it
[self.navigationController pushViewController:pdvController animated:YES];
edit summing op, the problem is that you don't have a navigation controller, so you can't push a view controller like that. What you can do, is pushing a view controller modally, using
[self presentModalViewController:pdvController animated:YES];
I've been staring at this for way too long.
There's nothing fancy happening here, and I've done this dozens of times, yet Interface Builder steadfastly refuses to provide me an action target for -(IBAction)slideDirections. I'm at the point where I'm willing to post publicly and feel stupid. So let 'er rip.
Here's my .h:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface PulseDetailController : UIViewController {
NSDictionary *pulse;
IBOutlet MKMapView *map;
IBOutlet UIWebView *directions;
IBOutlet UIView *directionsSlider;
BOOL directionsExtended;
IBOutlet UILabel *vendor;
IBOutlet UILabel *offer;
IBOutlet UILabel *offerText;
IBOutlet UILabel *hours;
IBOutlet UILabel *minutes;
IBOutlet UILabel *seconds;
IBOutlet UILabel *distance
}
#property (nonatomic, retain) NSDictionary *pulse;
#property (nonatomic, retain) MKMapView *map;
#property (nonatomic, retain) UIWebView *directions;
#property (nonatomic, retain) UIView *directionsSlider;
#property (nonatomic) BOOL directionsExtended;
#property (nonatomic, retain) UILabel *vendor;
#property (nonatomic, retain) UILabel *offer;
#property (nonatomic, retain) UILabel *offerText;
#property (nonatomic, retain) UILabel *hours;
#property (nonatomic, retain) UILabel *minutes;
#property (nonatomic, retain) UILabel *seconds;
#property (nonatomic, retain) UILabel *distance;
-(IBAction)slideDirections;
#end
Shouldn't the IBAction have a sender parameter?
Like:
-(IBAction)slideDirections:(id)sender;
Sometimes Interface Builder seems to get out of sync with classes in Xcode. Have you tried forcing interface builder to reread your PulseDetailController header file? (File -> Read Class Files... -> Select 'PulseDetailController.h'). This should force Interface Builder to see your new action.
Which objects are you trying to connect?
From your header, the logical choice would be UIView *directionsSlider
If you are ctrl dragging from directionsSlider to the "File's Owner" object, make sure that the Class in "File's Owner" is set to PulseDetailController.
So I'm declaring a NSMutableArray to hold 5 UIImageViews.
.h file:
#interface ImageDisplay : UIViewController {
IBOutlet UIImageView *img1;
IBOutlet UIImageView *img2;
IBOutlet UIImageView *img3;
IBOutlet UIImageView *img4;
IBOutlet UIImageView *img5;
NSMutableArray *imageHolderArray;
}
#property (nonatomic, retain) IBOutlet UIImageView *img1;
#property (nonatomic, retain) IBOutlet UIImageView *img2;
#property (nonatomic, retain) IBOutlet UIImageView *img3;
#property (nonatomic, retain) IBOutlet UIImageView *img4;
#property (nonatomic, retain) IBOutlet UIImageView *img5;
#property (nonatomic, retain) IBOutlet NSMutableArray *imageHolderArray;
#end
In the .m file:
//All objects are synthesized, just easier not to crowd the screen
- (void)viewDidLoad {
[super viewDidLoad];
imageHolderArray = [[NSMutableArray alloc] initWithObjects: img1,img2,img3,img4,img5,nil];
NSLog(#"imageHolderArray count: %i",[imageHolderArray count]); //Returns count of 1
}
So my question is, why is this happening? Why isn't it picking up all the objects in the Array? I'm not well versed in Objective-C programming so I'd appreciate it if someone could clue me in here. Thank you.
Because you didn't wire the IBOutlets to their views in Interface Builder. Looks like you probably wired img1, but didn't wire img2, so img2 is nil, which marks the end of your list of objects for -initWithObjects: even if later outlets are wired.