unable to hook to a ui view inside interface - objective-c

I am using THEOS, and I know how to hook to methods and override and stuff. But now what I want to do is, I want to access the UI views that are declared within (#interface).
Here is the header file I am referring to:
#class NSString, UILabel, UINavigationBar, UISwitch;
__attribute__((visibility("hidden")))
#interface SettingsViewController : UIViewController <UINavigationBarDelegate, UIBarPositioningDelegate>
{
UINavigationBar *navBar;
UISwitch *alertSwitch;
UISwitch *lightSwitch;
UISwitch *lockSwitch;
UISwitch *infoSwitch;
UILabel *alertLabel;
UILabel *lightLabel;
UILabel *lockLabel;
UILabel *showInfoLabel;
UILabel *infoLabel;
}
#property(retain, nonatomic) UILabel *infoLabel; // #synthesize infoLabel;
#property(retain, nonatomic) UILabel *showInfoLabel; // #synthesize showInfoLabel;
#property(retain, nonatomic) UILabel *lockLabel; // #synthesize lockLabel;
#property(retain, nonatomic) UILabel *lightLabel; // #synthesize lightLabel;
#property(retain, nonatomic) UILabel *alertLabel; // #synthesize alertLabel;
#property(retain, nonatomic) UISwitch *infoSwitch; // #synthesize infoSwitch;
#property(retain, nonatomic) UISwitch *lockSwitch; // #synthesize lockSwitch;
#property(retain, nonatomic) UISwitch *lightSwitch; // #synthesize lightSwitch;
#property(retain, nonatomic) UISwitch *alertSwitch; // #synthesize alertSwitch;
#property(retain, nonatomic) UINavigationBar *navBar; // #synthesize navBar;
- (void).cxx_destruct;
- (void)didReceiveMemoryWarning;
- (void)dismissSettingsViewController;
- (long long)preferredStatusBarStyle;
- (void)showDevInfo;
- (void)infoSwitchSwitched;
- (void)lockSwitchSwitched;
- (void)lightSwitchSwitched;
- (void)alertSwitchSwitched;
- (void)viewDidLoad;
- (long long)positionForBar:(id)arg1;
// Remaining properties
#property(readonly, copy) NSString *debugDescription;
#property(readonly, copy) NSString *description;
#property(readonly) unsigned long long hash;
#property(readonly) Class superclass;
#end
I want to access the UI views under #interface (Ex: UISwitch *alertSwitch;).
How can I access it? Please help I am trying to figure it out since three days :(. Any help or suggestion is very very appreciated.

I hope this help
%hook SettingsViewController
-(void) WhereEverYouWantToRunYourCode {
self.alertSwitch = ....
}
%end

Related

Changing label's data using textField inout

I want to change the label's text (which is embedded in a tableViewCell) using a textField data (which is embedded outside the tableViewCell).
Can anyone share the code please using objective-C.
Here is my TableViewCell.h file.
#import <UIKit/UIKit.h>
#interface TableViewCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UILabel *label1;
#property (strong, nonatomic) IBOutlet UILabel *label2;
#end
Here is my storyboard controller file
#import <UIKit/UIKit.h>
#interface ViewController:UIViewController<UITableViewDelegate,UITableViewDataSource>
{
NSMutableArray *contacts;
}
- (IBAction)leftBtn:(id)sender;
- (IBAction)rightBtn:(id)sender;
- (IBAction)nextBtn:(id)sender;
- (IBAction)SendBtn:(id)sender;
#property (strong, nonatomic) IBOutlet UITableView *tabV1;
#property (strong, nonatomic) IBOutlet UITextField *txtField;
#end
Here I have the button action connection where I should I write the actual code to change the label's data using a text field.
- (IBAction)leftBtn:(id)sender {
}

UISlider values

I'm trying to create an app that has three UISlider used for selecting R, G and B values. The slider should change the colour of a label according to the sliders values.
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
NSInteger color;
IBOutlet UISlider *redSlider;
IBOutlet UISlider *greenSlider;
IBOutlet UISlider *blueSlider;
IBOutlet UILabel *colorLabel;
}
#property (nonatomic, retain) UISlider *redSlider;
#property (nonatomic, retain) UISlider *greenSlider;
#property (nonatomic, retain) UISlider *blueSlider;
colorLabel.textColor = [UIColor colorWithRed: redSlider.value green:greenSlider.value
blue:blueSlider.value alpha:1];
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#synthesize redSlider, greenSlider, blueSlider;
#end
This is what I have so far and I'm totally stuck.
You can do this like...
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
// you need to make sure these are actually created
// and give them all a target of self and action sliderValueChanged
#property (nonatomic, retain) UISlider *redSlider;
#property (nonatomic, retain) UISlider *greenSlider;
#property (nonatomic, retain) UISlider *blueSlider;
// not sure where this is set up
#property (nonatomic, strong) UILabel *colorLabel;
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// You may have to create your labels and sliders in here...
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)sliderValueChanged
{
// the sliders have changed so set the colour of the label
// based on the new values of the sliders.
self.colorLabel.textColor = [UIColor colorWithRed:self.redSlider.value
green:self.greenSlider.value
blue:self.blueSlider.value
alpha:1.0];
}
#end
Because you don't actually have a question I'm going to take a guess that your code doesn't compile, because it wouldn't.
colorLabel.textColor = [UIColor colorWithRed: redSlider.value green:greenSlider.value blue:blueSlider.value alpha:1];
The above line doesn't belong in you interface. I would recommend you change the code you currently have to something like.
ViewController.h
#interface ViewController : UIViewController
// You don't need the ivars anymore these get generated with the properties below
#property (nonatomic, retain) IBOutlet UISlider *redSlider;
#property (nonatomic, retain) IBOutlet UISlider *greenSlider;
#property (nonatomic, retain) IBOutlet UISlider *blueSlider;
#property (nonatomic, retain) IBOutlet UILabel *colorLabel
#property (assign) NSInteger color;
#end
ViewController.m
#implementation ViewController
// Also no need for the synthesize as these also get generated automatically
- (void)viewDidLoad
{
[super viewDidLoad];
// To change the actual color when changing the value of a slider move this to a method that gets called on slider changed.
colorLabel.textColor = [UIColor colorWithRed:self.redSlider.value green:self.greenSlider.value self.blue:blueSlider.value alpha:1];
}
#end
And once you actually ask a question I might also be able to help you with that.
Your ViewController.h :-
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
IBOutlet UISlider *redSlider;
IBOutlet UISlider *greenSlider;
IBOutlet UISlider *blueSlider;
IBOutlet UILabel *colorLabel;
}
#property (nonatomic, retain) UISlider *redSlider;
#property (nonatomic, retain) UISlider *greenSlider;
#property (nonatomic, retain) UISlider *blueSlider;
#end
and your ViewController.m will be like this:-
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize redSlider, greenSlider, blueSlider;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self changeLabelColor];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(Void) changeLabelColor
{
colorLabel.backgroundcolor = [UIColor colorWithRed:redSlider.value green:redSlider.value blue:redSlider.value alpha:1.0];
}
#end
As i didn’t copied paste and i have written it, there might be some typo..
textcolor wouldn’t change label color so i changed it to backgroundcolor.
you can also add slider method with IBAction.

UITextField bind

I can't figure out why that code is not working for me.
ViewController.h
...
#property (nonatomic, copy) UITextField *textField;
...
ViewController.m
-(void)viewDidLoad
{
[self.textField addTarget:self
action:#selector(textIsChanged:)
forControlEvents:UIControlEventEditingChanged];
}
-(void)textIsChanged:(id)sender;
{
NSLog(#"Changed");
}
When I type something in the textField textIsChanged method is never invoked.
You should declare textField as an IBOutlet like this:
#property (nonatomic, retain) IBOutlet UITextField *textField;
or, if you are using ARC (Automatic Reference Counting):
#property (nonatomic, strong) IBOutlet UITextField *textField;
and bind it from the xib file in interface builder.

Textfield return (null) no matter what

I have searched stackoverflow for similar problems and have found some, but they did not resolve my problem. I have 3 textfields (name,address,phone) from which I want to get the text. I have declared them in the (.h) file, also the #property, and then #synthesized them in the (.m) file. I have a IBAction for a button declared in the (.h) file and linked up correctly. Now when I push this button I want to get the values from the textfields but NSLog shows they are all (null) even before I do anything with the textfields. Its very simple code, i can't understand why it returns null.
//CoreDataViewController.h
#interface coreDataViewController : UIViewController {
UITextField *name;
UITextField *address;
UITextField *phone;
UILabel *status;
}
#property (strong, retain) IBOutlet UITextField *name;
#property (strong, retain) IBOutlet UITextField *address;
#property (strong, retain) IBOutlet UITextField *phone;
#property (strong, retain) IBOutlet UILabel *status;
- (IBAction) saveData;
#end
//CoreDataViewController.m
#import "coreDataViewController.h"
#import "AppDelegate.h"
#implementation coreDataViewController
#synthesize name=_name;
#synthesize phone=_phone;
#synthesize address=_address;
#synthesize status=_status;
- (void) saveData
{
NSLog(#"Name %# Address %# Phone %#",self.name.text,self.address.text,self.phone.text);
...some more code (commented out)....
}
IMO you have incorrectly synthesized iVars.
You use syntax:
synthesize name=_name;
but in the .h file you have:
#interface coreDataViewController : UIViewController {
UITextField *name;
UITextField *address;
UITextField *phone;
UILabel *status;
}
Change this part to:
#interface coreDataViewController : UIViewController {
UITextField *_name;
UITextField *_address;
UITextField *_phone;
UILabel *_status;
}
Just change below code
write synthesize like this
#synthesize name;
#synthesize phone;
#synthesize address;
#synthesize status;
ratherthen
#synthesize name=_name;
#synthesize phone=_phone;
#synthesize address=_address;
#synthesize status=_status;

program received signal sigabrt in Ipad program

I fix all warnings and now I have such error in my AppDelegate Class
.h file is
#import <UIKit/UIKit.h>
#interface UYLAppDelegate : UIResponder <UIApplicationDelegate>{
}
#property (retain, nonatomic) IBOutlet UIWindow *window;
#property (retain, nonatomic) IBOutlet UISplitViewController *splitViewController;
#end
.m file is
#import "UYLAppDelegate.h"
#import "UYLMasterViewController.h"
#import "UYLDetailViewController.h"
#import <QuartzCore/QuartzCore.h>
#implementation UYLAppDelegate
#synthesize window = _window;
#synthesize splitViewController = _splitViewController;
- (void)dealloc
{
[_window release];
[_splitViewController release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIView *rootView = [[self.splitViewController.viewControllers objectAtIndex:0] view];
rootView.layer.borderWidth = 1.0f;
rootView.layer.cornerRadius =5.0f;
rootView.layer.shadowOpacity = 0.8f;
rootView.layer.shadowOffset = CGSizeMake(-5, 0);
self.window.rootViewController = self.splitViewController; //error here
[self.window makeKeyAndVisible];
return YES;
}
#end
in this row I take an error
self.window.rootViewController = self.splitViewController; //error here
SplitViewController consist of 2 controllers, .h file are:
#import <UIKit/UIKit.h>
#class UYLDetailViewController;
#interface UYLMasterViewController : UITableViewController
#property (retain, nonatomic) IBOutlet UYLDetailViewController *detailViewController;
#end
and the second
#import <UIKit/UIKit.h>
#import "UYLModalViewController.h"
#class UYLMasterViewController;
#interface UYLDetailViewController : UIViewController <UYLModalViewControllerDelegate>{
UIBarButtonItem *_MessageButton;
NSInteger modalViewShowType;
}
-(IBAction)buttonTapped:(id)sender;
#property (retain, nonatomic, getter=_MessageButton) IBOutlet UIBarButtonItem *someMessageButton;
#property (retain, nonatomic) NSNumber *detailItem;
#property (retain, nonatomic) IBOutlet UIToolbar *toolbar;
#property (retain, nonatomic) IBOutlet UILabel *detailTitle;
#property (retain, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
#property (assign, nonatomic) BOOL masterIsVisible;
#end
edit:
there is all I see in console
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug 15 16:03:10 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 8217.
Pending breakpoint 1 - ""UYLDetailViewController.m":117" resolved
Pending breakpoint 2 - ""UYLModalViewController.m":30" resolved
Pending breakpoint 3 - ""UYLModalViewController.m":41" resolved
Pending breakpoint 4 - ""UYLDetailViewController.m":63" resolved
Pending breakpoint 5 - ""UYLMasterViewController.m":46" resolved
Pending breakpoint 7 - ""UYLDetailViewController.m":36" resolved
No breakpoint number 7.
Current language: auto; currently objective-c
Please help me to understand it =(
I had some SIGABRT errors most of the time, it just means that it can't find that instance you are referring to. So look at that line again and think what might not be declared right.
I think it might help if you change it to.
self.window.rootViewController = splitViewController;