2012-02-03 28 views

回答

4

不要做它在一行。这样做很容易理解。引用Brian Kernighan:

大家都知道,调试的难度是编写程序的两倍。所以,如果你写的时候你的聪明才智,你将如何进行调试?

2

如果所有这些都符合KVC,并且您想要放入相同的值,则可以将所有这些放在数组中,然后设置文本。

[[NSArray arrayWithObjects:wage, hours, grossPay, taxes, netPay, nil] setValue:@"" forKey:@"text"]; 

或者hoshi的想法也不错。 (再次它需要遵守KVC)

非KVC解决方案:

[[NSArray arrayWithObjects:wage, hours, grossPay, taxes, netPay, nil] makeObjectsPerformSelector:@selector(setText:) withObject:@""]; 
0

使用一个模型类,如:

@interface DbInfos : NSObject{ 
    NSString *wage; 
    NSString *hours; 
    NSString *grossPay; 
    NSString *taxes; 
    NSString *netPay; 
} 

@property(nonatomic,strong)NSString *wage; 
@property(nonatomic,strong)NSString *hours; 
@property(nonatomic,strong)NSString *grossPay; 
@property(nonatomic,strong)NSString *taxes; 
@property(nonatomic,strong)NSString *netPay; 

-(id)initWithWage:(NSString *)newWage Hours:(NSString *)newHours GrossPay:(NSString *)newTaxes NetPay:(NSString *)newNetPay; 
0

同意与这一个罗布(+1),但对于回答乐趣

for (UILabel * at in [NSArray arrayWithObjects:wage, hours, grossPay, taxes, netPay, nil]) at.text = @""; 

注意,这会失败如果wage,hoursgrossPaytaxesnil

相关问题