我对UITableView有一个奇怪的问题:我的tableview显示了用户可以从中选择一个对象的名称.该值已保存.当tableview出现时,选择该行(在cellForRowAtIndexPath中).但是在viewWillAppear中,首先选择行然后取消选择.您可以看到它是第一次被选中,因为蓝色背景会在短时间内发生.
我已经设定
self.clearsSelectionOnViewWillAppear = NO;
但这不起作用.请有人帮帮我!提前致谢.
这里有一些示例代码:
#import "ECTESTTableViewController.h"
@interface ECTESTTableViewController ()
@end
@implementation ECTESTTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.clearsSelectionOnViewWillAppear = NO;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 8;
}
- (UITableViewCell …Run Code Online (Sandbox Code Playgroud) 我尝试将浮点值转换为字符串并使用 NSNumberFormatter。我制作了一个舍入函数并使用格式化程序来表示字符串。格式化程序应该只处理区域设置和小数点符号。我最终得到了错误的值。的结果
NSNumberFormatter *_numberFormatter = [[NSNumberFormatter alloc] init];
[_numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[_numberFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"de_DE"]];
[_numberFormatter setMaximumFractionDigits:2];
[_numberFormatter setRoundingMode: NSNumberFormatterRoundDown];
NSString* sumString = [_numberFormatter stringFromNumber:[NSNumber numberWithFloat:14.2f]];
Run Code Online (Sandbox Code Playgroud)
是“14,19”。我不明白为什么当小数点仅为 1 时该值要向下舍入。舍入模式在这里不应该执行任何操作,或者我错了。我可以使用“NSNumberFormatterRoundUp”,但在某些情况下结果可能是“14,21”?