Why doesn't IB see my IBAction? - iphone

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.

Related

How to subclass UITextView

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;
}

Load a view .xib in MainWindow.xib

It`s probably a very silly mistake, but I've spent over 4 days looking for a solution for this.
It is very simple, I´ve got my MainView.xib and a view called FirstViewController (h/m/xib).
In MainWindow.xib I add a UIViewController and change the class name to FirstViewController and set the Nib name also (altouhg I've tried both ways).
I guess it has to do something with outlets, but I can`t really tell, as I am a newbie developing for iOS, any help wil REALLY help a lot.
Im using XCode 3.2 and interface builder, with SDK 4.3
AppDelegate
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#interface iPadTerritorioV2AppDelegate : NSObject <UIApplicationDelegate> {
IBOutlet UIWindow *window;
IBOutlet UIViewController *navigationController;
NSString *devToken;
NSString *matricula;
NSString *campus;
NSMutableArray *materiasAlumno; //para CCM
NSMutableArray *busqDir; //para CCM
NSInteger agendaBadgeNumber;
NSInteger intramurosBadgeNumber;
NSInteger notificacionesBadgeNumber;
NSInteger mapaBadgeNumber;
NSMutableData *receivedData;
NSMutableDictionary *listData;
BOOL yaSeHizoElPrimerFetchBadges;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UIViewController *navigationController;
#property (nonatomic, retain) NSString *devToken;
#property (nonatomic, retain) NSString *matricula;
#property (nonatomic, retain) NSString *campus;
#property (nonatomic, retain) NSMutableArray *materiasAlumno;
#property (nonatomic, retain) NSMutableArray *busqDir;
#property NSInteger agendaBadgeNumber;
#property NSInteger intramurosBadgeNumber;
#property NSInteger notificacionesBadgeNumber;
#property NSInteger mapaBadgeNumber;
#property (nonatomic, retain) NSMutableData *receivedData;
#property (nonatomic, retain) NSMutableDictionary *listData;
#property BOOL yaSeHizoElPrimerFetchBadges;
- (void)fetchBadges;
#end
FirstViewController.h
#import <UIKit/UIKit.h>
#import "Constants.h"
#import "StringDecoding.h"
#define kConnectionBadgeNotifications 0
#define kConnectionLogin 1
#define kConnectionDevToken 2
#define kCCMindex 0
#define kCSFindex 1
#define kMTYindex 2
#interface FirstViewController : UIViewController {
IBOutlet UISegmentedControl *segmentedCampus;
IBOutlet UITextField *usernameField;
IBOutlet UITextField *passwordField;
IBOutlet UISwitch *remembermeSwitch;
IBOutlet UIButton *loginButton;
UIActivityIndicatorView *loginIndicator;
NSMutableDictionary *listData;
NSMutableData *receivedData;
NSInteger connectionID;
}
#property (nonatomic, retain) UISegmentedControl *segmentedCampus;
#property (nonatomic, retain) UITextField *usernameField;
#property (nonatomic, retain) UITextField *passwordField;
#property (nonatomic, retain) UIActivityIndicatorView *loginIndicator;
#property (nonatomic, retain) UISwitch *remembermeSwitch;
#property (nonatomic, retain) UIButton *loginButton;
#property (nonatomic, retain) NSMutableDictionary *listData;
#property (nonatomic, retain) NSMutableData *receivedData;
#property NSInteger connectionID;
- (IBAction)handleNextClick:(id) sender;
- (IBAction)backgroundClick;
- (IBAction)login: (id) sender;
#end
It sounds like your FirstViewController isn't being retained - if it's not assigned to an outlet anywhere, nothing's retaining it and it'll just disappear. Add a property somewhere (your AppDelegate, perhaps, if that's all you've got) and connect it to the controller:
#property (nonatomic, retain) IBOutlet UIViewController *firstViewController;

IBOutlet is not recognized by Interface Builder when conditioning compiling in Interface declaration

If I add this conditioning compiling flag in my header file, which is a owner of a xib file, the xib file cannot read the IBOutlet and show as missing. And gives warnings.
In runtime it works fine. Did anybody experience the same problem?
/* MFMessageComposeViewControllerDelegate is available in iOS 4.0 and later. */
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
#interface SendMoneyResponseVC : UITableViewController
<UINavigationControllerDelegate, MFMessageComposeViewControllerDelegate,
MFMailComposeViewControllerDelegate, UIActionSheetDelegate>
#else
#interface SendMoneyResponseVC : UITableViewController
<UINavigationControllerDelegate,
MFMailComposeViewControllerDelegate, UIActionSheetDelegate>
#endif
{
IBOutlet UITableView *sendMoneyTableVC;
IBOutlet UITableViewCell *refNumRemittanceCell;
IBOutlet UILabel *refNumLabel, *refNumValueLabel, *refNumInfoLabel;
IBOutlet UITableViewCell *refNumDomesticCell;
IBOutlet UILabel *domesticInfoLabel, *feeAndReferenceLabel;
IBOutlet UITableViewCell *shareRefNumCell;
IBOutlet UIButton *shareRefNumButton;
NSString *referenceNumber, *recipient, *currency, *mtoName;
float amount, fee;
int sendMoneyType;
UIAlertView *smsAlertView;
}
#property (nonatomic, retain) UITableView *sendMoneyTableVC;
#property (nonatomic, retain) UITableViewCell *refNumRemittanceCell;
#property (nonatomic, retain) UILabel *refNumLabel, *refNumValueLabel, *refNumInfoLabel;
#property (nonatomic, retain) UITableViewCell *refNumDomesticCell;
#property (nonatomic, retain) UILabel *domesticInfoLabel, *feeAndReferenceLabel;
#property (nonatomic, retain) UITableViewCell *shareRefNumCell;
#property (nonatomic, retain) UIButton *shareRefNumButton;
#property (nonatomic, retain) NSString *referenceNumber, *recipient, *currency, *mtoName;
#property float amount, fee;
#property int sendMoneyType;
- (IBAction) didPressShareButton;
#end
Have you tried restructuring your code in a way which is equivalent to the compiler, but is less likely to confuse Interface Builder? Something like this:
#interface SendMoneyResponseVC : UITableViewController
<UINavigationControllerDelegate,
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
MFMessageComposeViewControllerDelegate,
#endif
MFMailComposeViewControllerDelegate,
UIActionSheetDelegate>
{ ... }
#end
This way there will be only one #interface/#end pair.
what is the reason for doing this? Unless you want to compile with an outdated SDK you should get rid of this.
Interface Builder doesn't preprocess your files, so it will see two #interfaces and one #end.
And interface builder can't parse something like this.

iPad/iPhone TableVIew help pushing a new view

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];

iPhone UIImageView Array

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.