最小フォント スケールまたはサイズが設定されたセルから単一の単語で構成される NSString の値を渡そうとすると、NSLogs でのチェックが機能するように見えますが、別の文字列と比較しようとするとそれは私に [NSNull length] unrecognized selector sent などを与えます。より多くの単語で構成された文字列を使用すると、正常に機能します。Xcode 7のバグだと思います。他の誰かがそれを経験しましたか? 回避策はありますか?
プログラムとInterfece Builderの両方でセルにラベルを設定しようとしましたが、同じ結果になりました。私のカスタムテーブルビューセルは次のとおりです
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"aCell"];
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"aCell" forIndexPath:indexPath];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.contentView.backgroundColor = [UIColor colorWithRed:165.0/255.0 green:15.0/255.0 blue:2.0/255.0 alpha:1];
cell.textLabel.backgroundColor = [UIColor colorWithRed:165.0/255.0 green:15.0/255.0 blue:2.0/255.0 alpha:1];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.font = [UIFont fontWithName:@"AvenirNext-Medium" size:22.0f];
cell.textLabel.textColor = [UIColor colorWithRed:243.0/255.0 green:243.0/255.0 blue:243.0/255.0 alpha:1];
UIView * separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, 2)];
separatorLineView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"QastItBackground"]];
[cell.contentView addSubview:separatorLineView];
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.minimumScaleFactor = 0.5;
NSDictionary *categories = [Options categories];
NSArray *details = [categories objectForKey:self.title];
NSString *detail = details [indexPath.row];
cell.textLabel.text = detail;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[self tableView] cellForRowAtIndexPath:indexPath];
NSString *selection = cell.textLabel.text;
[[TemporarySelection sharedStore]updateSelection:selection];
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
if ([self.title isEqualToString:@"Two Ways"]) {
TwoWaysViewController *twvc = [[TwoWaysViewController alloc]init];
twvc = (TwoWaysViewController *)[storyboard instantiateViewControllerWithIdentifier:@"TwoWays"];
[self presentViewController:twvc animated:YES completion:nil];
CFRunLoopWakeUp(CFRunLoopGetCurrent());
} else {
DieFacesViewController *dfvc = (DieFacesViewController *)[storyboard instantiateViewControllerWithIdentifier:@"DieFaces"];
[self presentViewController:dfvc animated:YES completion:nil];
CFRunLoopWakeUp(CFRunLoopGetCurrent());
}
}
次に、新しいView Controllerでシングルトンから値を取得し、それを別の文字列と比較します
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
NSString *ts = [[TemporarySelection sharedStore]temporarySelection];
NSArray *favourites = [[FavouritesStore sharedStore]allFavourites];
NSArray *selectedFaces = [[SelectedStore sharedStore]selectedOptions];
UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"selectorbg"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
self.selectionName.text = ts;
NSLog(@"%@", ts);
NSLog(@"%@", selectedFaces[0] );
if ([self.selectionName.description isEqualToString: selectedFaces[0]]) {
self.faceOne.image = [UIImage imageNamed:@"face1red"];
} else if (selectedFaces[0] == [NSNull null]) {
self.faceOne.image = [UIImage imageNamed:@"face1white"];
} else {
self.faceOne.image = [UIImage imageNamed:@"face1grey"];
}
}
NSLog は正しい文字列を示し、ブレークポイントを使用すると、最初の if ステートメントまですべてがスムーズになります。それを削除すると、2 番目のステートメントは問題ないので、問題は *ts NSString にあるはずです。インターフェイスビルダーを介してカスタムクラスセルを持つ別のテーブルビューがあり、同じ問題があります。非常に混乱するように聞こえるかもしれませんが、考えられることはすべて試してみましたが、それが原因のようです.