当我尝试传递由具有最小字体比例或大小设置的单元格中的单个单词组成的 NSString 的值时,它似乎可以使用 NSLogs 进行检查,但是当我尝试将其与另一个字符串进行比较时它给了我一个 [NSNull length] 无法识别的选择器发送等。使用由更多单词组成的字符串,它可以正常工作。我认为这是 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());
}
}
然后在新的视图控制器中,我从单例中获取值,并将其与另一个字符串进行比较
-(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 语句。如果我删除它,第二个语句就可以了,所以问题必须出在 *ts NSString 上。我通过界面生成器有另一个带有自定义类单元格的表格视图,它也有同样的问题。我知道这听起来很令人困惑,但我尝试了我能想到的一切,这似乎就是原因。