小编cor*_*ban的帖子

UITableViewCell不断取消选择

我对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)

iphone objective-c uitableview ios

2
推荐指数
1
解决办法
708
查看次数

带有 2 位小数的 NSNumberFormatter 会导致奇怪的结果

我尝试将浮点值转换为字符串并使用 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”?

objective-c ios

0
推荐指数
1
解决办法
516
查看次数

标签 统计

ios ×2

objective-c ×2

iphone ×1

uitableview ×1