Created
July 10, 2012 21:47
-
-
Save chyld/3086429 to your computer and use it in GitHub Desktop.
ios string concat and type conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (IBAction)concatFields:(id)sender | |
{ | |
//NSString* s = field1.text; | |
//label.text = [s stringByAppendingString:field2.text]; | |
float f1 = field1.text.floatValue; | |
float f2 = field2.text.floatValue; | |
NSNumber* n = [NSNumber numberWithFloat:f1*f2]; | |
label.text = n.stringValue; | |
} | |
- (IBAction)segmentSelected | |
{ | |
NSNumber *n = [NSNumber numberWithInteger:[segment selectedSegmentIndex]]; | |
NSString *s = [n stringValue]; | |
[label setText:s]; | |
} | |
- (IBAction)sliding | |
{ | |
NSNumber *n = [NSNumber numberWithFloat:[slider value]]; | |
label.text = [n stringValue]; | |
} | |
- (IBAction)switching | |
{ | |
BOOL b = [theswitch isOn]; | |
} | |
- (IBAction)stepping | |
{ | |
NSNumber *n1 = [NSNumber numberWithDouble:[stepper value]]; | |
[label setText:[n1 stringValue]]; | |
} | |
@interface TMViewController : UIViewController | |
@property (strong, nonatomic) IBOutlet UITextView *text; | |
@property (strong, nonatomic) IBOutlet UIWebView *web; | |
@property (strong, nonatomic) IBOutlet UIImageView *imageview; | |
@property (strong, nonatomic) IBOutlet UILabel *label; | |
- (IBAction)button:(id)sender forEvent:(UIEvent *)event; | |
- (IBAction)segment:(id)sender forEvent:(UIEvent *)event; | |
@end | |
- (IBAction)segment:(id)sender forEvent:(UIEvent *)event { | |
NSInteger i = [sender selectedSegmentIndex]; | |
NSNumber *n = [NSNumber numberWithInt:i]; | |
label.text = [n stringValue]; | |
label.text = [text text]; | |
switch ([sender selectedSegmentIndex]) { | |
case 0: | |
[imageview setImage:[UIImage imageNamed:@"sexy.jpg"]]; | |
break; | |
case 1: | |
[imageview setImage:[UIImage imageNamed:@"objc.png"]]; | |
break; | |
case 2: | |
[imageview setImage:[UIImage imageNamed:@"love.jpg"]]; | |
break; | |
case 3: | |
[web loadRequest: | |
[NSURLRequest requestWithURL: | |
[NSURL URLWithString:@"http://google.com"]]]; | |
break; | |
default: | |
break; | |
} | |
} | |
@interface TMPickerViewController : UIViewController | |
<UIPickerViewDataSource, UIPickerViewDelegate> | |
{ | |
NSMutableArray *list; | |
} | |
@property (weak, nonatomic) IBOutlet UILabel *label; | |
@property (weak, nonatomic) IBOutlet UIPickerView *picker; | |
@end | |
@implementation TMPickerViewController | |
@synthesize label; | |
@synthesize picker; | |
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { | |
return 1; | |
} | |
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { | |
return [list count]; | |
} | |
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { | |
return [list objectAtIndex:row]; | |
} | |
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { | |
[label setText:[list objectAtIndex:row]]; | |
} | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
list = [[NSMutableArray alloc] init]; | |
[list addObject:@"A"]; | |
[list addObject:@"B"]; | |
[list addObject:@"C"]; | |
} | |
- (void)viewDidUnload { | |
[self setLabel:nil]; | |
[self setPicker:nil]; | |
[super viewDidUnload]; | |
} | |
@end | |
- (IBAction)satellite:(id)sender forEvent:(UIEvent *)event { | |
[map setMapType:MKMapTypeSatellite]; | |
} | |
- (IBAction)datepick:(id)sender forEvent:(UIEvent *)event { | |
NSDate *pickerDate = [sender date]; | |
NSString *selectionString = [[NSString alloc] initWithFormat:@"%@", | |
[pickerDate description]]; | |
label.text = selectionString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment