从UITextfield

时间:2016-08-21 10:08:16

标签: ios objective-c uitextfield

我一直在研究iOS的小货币转换器,并希望从UITextField读取一个浮点数。不幸的是,我无法从UITextField读取浮点数。我在互联网上做了一些研究,但我试过的方法都没有。我是Objective-C的新手,这是我自己的第一篇文章,所以请随时向我提供反馈和建议。

这是ViewController.m中的代码:

//
//  ViewController.m
//  Currencyz
//
//  Created by Daniel Putzer on 21/08/16.
//  Copyright © 2016 Daniel Putzer. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize Dollar, Euro, DollarValue, EuroValue, Result, ReadIn;

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setDollar: 0];
    [self setResult: @""];
}

- (IBAction) ReadEuro:(id)sender
{
    Euro = [EuroValue.text floatValue];
}

- (void) Calculate
{
    Dollar = 1.13245 * Euro;
    Result = [NSString stringWithFormat: @"%.2f", Dollar];
}

- (IBAction)CalculateDollar:(id)sender
{
    [self Calculate];
    [DollarValue setText: Result];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

这里是ViewController.h:

//
//  ViewController.h
//  Currencyz
//
//  Created by Daniel Putzer on 21/08/16.
//  Copyright © 2016 Daniel Putzer. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    float Euro;
    float Dollar;
    NSString *Result;
    NSString *ReadIn;

    IBOutlet UILabel *DollarValue;
    IBOutlet UITextField *EuroValue;
}

@property float Euro;
@property float Dollar;
@property NSString *Result;
@property NSString *ReadIn;

@property IBOutlet UILabel *DollarValue;
@property IBOutlet UITextField *EuroValue;

@end

我不明白为什么它不会将变量Euro设置为UITextField中输入的金额。

1 个答案:

答案 0 :(得分:1)

jack@jw-xubuntu-desk1:~/Documents/apache/httpd-2.4.23$ make
Making all in srclib
make[1]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/srclib'
make[1]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/srclib'
Making all in os
make[1]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/os'
Making all in unix
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/os/unix'
make[3]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/os/unix'
make[3]: Nothing to be done for 'local-all'.
make[3]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/os/unix'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/os/unix'
make[1]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/os'
Making all in server
make[1]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/server'
Making all in mpm
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/server/mpm'
Making all in event
make[3]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/server/mpm/event'
make[4]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/server/mpm/event'
make[4]: Nothing to be done for 'local-all'.
make[4]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/server/mpm/event'
make[3]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/server/mpm/event'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/server/mpm'
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/server'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/server'
make[1]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/server'
Making all in modules
make[1]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules'
Making all in aaa
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/aaa'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/aaa'
Making all in cache
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/cache'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/cache'
Making all in core
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/core'
make[3]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/core'
make[3]: Nothing to be done for 'local-all'.
make[3]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/core'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/core'
Making all in database
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/database'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/database'
Making all in debugging
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/debugging'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/debugging'
Making all in filters
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/filters'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/filters'
Making all in http
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/http'
make[3]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/http'
make[3]: Nothing to be done for 'local-all'.
make[3]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/http'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/http'
Making all in ldap
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/ldap'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/ldap'
Making all in loggers
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/loggers'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/loggers'
Making all in metadata
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/metadata'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/metadata'
Making all in proxy
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/proxy'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/proxy'
Making all in session
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/session'
make[2]: Leaving directory '/home/jack/DoThankyou!cuments/apache/httpd-2.4.23/modules/session'
Making all in slotmem
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/slotmem'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/slotmem'
Making all in ssl
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/ssl'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/ssl'
Making all in proxy/balancers
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/proxy/balancers'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/proxy/balancers'
Making all in arch/unix
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/arch/unix'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/arch/unix'
Making all in dav/main
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/dav/main'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/dav/main'
Making all in generators
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/generators'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/generators'
Making all in dav/fs
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/dav/fs'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/dav/fs'
Making all in mappers
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/modules/mappers'
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules/mappers'
make[1]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/modules'
Making all in support
make[1]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/support'
make[2]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23/support'
make[2]: Nothing to be done for 'local-all'.
make[2]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/support'
make[1]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23/support'
make[1]: Entering directory '/home/jack/Documents/apache/httpd-2.4.23'
x86_64-linux-gnu-gcc  -pthread      -DLINUX -D_REENTRANT -D_GNU_SOURCE     -I. -I/home/jack/Documents/apache/httpd-2.4.23/os/unix -I/home/jack/Documents/apache/httpd-2.4.23/include -I/usr/include/apr-1.0 -I/usr/include -I/usr/local/pcre/include -I/home/jack/Documents/apache/httpd-2.4.23/modules/aaa -I/home/jack/Documents/apache/httpd-2.4.23/modules/cache -I/home/jack/Documents/apache/httpd-2.4.23/modules/core -I/home/jack/Documents/apache/httpd-2.4.23/modules/database -I/home/jack/Documents/apache/httpd-2.4.23/modules/filters -I/home/jack/Documents/apache/httpd-2.4.23/modules/ldap -I/home/jack/Documents/apache/httpd-2.4.23/modules/loggers -I/home/jack/Documents/apache/httpd-2.4.23/modules/lua -I/home/jack/Documents/apache/httpd-2.4.23/modules/proxy -I/home/jack/Documents/apache/httpd-2.4.23/modules/session -I/home/jack/Documents/apache/httpd-2.4.23/modules/ssl -I/home/jack/Documents/apache/httpd-2.4.23/modules/test -I/home/jack/Documents/apache/httpd-2.4.23/server -I/home/jack/Documents/apache/httpd-2.4.23/modules/arch/unix -I/home/jack/Documents/apache/httpd-2.4.23/modules/dav/main -I/home/jack/Documents/apache/httpd-2.4.23/modules/generators -I/home/jack/Documents/apache/httpd-2.4.23/modules/mappers  -c /home/jack/Documents/apache/httpd-2.4.23/server/buildmark.c
/usr/share/apr-1.0/build/libtool --silent --mode=link x86_64-linux-gnu-gcc  -pthread         -o httpd  modules.lo buildmark.o -export-dynamic server/libmain.la modules/core/libmod_so.la modules/http/libmod_http.la server/mpm/event/libevent.la os/unix/libos.la      /usr/lib/x86_64-linux-gnu/libaprutil-1.la /usr/lib/x86_64-linux-gnu/libapr-1.la 
server/.libs/libmain.a(util_pcre.o): In function `ap_regfree':
util_pcre.c:(.text+0x109): undefined reference to `pcre_free'
server/.libs/libmain.a(util_pcre.o): In function `ap_regcomp':
util_pcre.c:(.text+0x196): undefined reference to `pcre_compile2'
util_pcre.c:(.text+0x1f4): undefined reference to `pcre_fullinfo'
server/.libs/libmain.a(util_pcre.o): In function `ap_regexec_len':
util_pcre.c:(.text+0x3b5): undefined reference to `pcre_exec'
server/.libs/libmain.a(util_pcre.o): In function `ap_regname':
util_pcre.c:(.text+0x5c3): undefined reference to `pcre_fullinfo'
util_pcre.c:(.text+0x5e3): undefined reference to `pcre_fullinfo'
util_pcre.c:(.text+0x603): undefined reference to `pcre_fullinfo'
collect2: error: ld returned 1 exit status
/home/jack/Documents/apache/httpd-2.4.23/build/program.mk:22: recipe for target 'httpd' failed
make[1]: *** [httpd] Error 1
make[1]: Leaving directory '/home/jack/Documents/apache/httpd-2.4.23'
/home/jack/Documents/apache/httpd-2.4.23/build/rules.mk:75: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

试试这个,看看是否打印出你的价值。