我想从UIPickerView获取2个值并将它们合并为一个字符串。我可以正确地获取它们,但是当我尝试NSLog时,最后一个NSString中的合并会继续与sigabrt崩溃。
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIPickerView *pickerView = (UIPickerView *)[actionSheet viewWithTag:101];
NSLog(@"Time:: %@%@",[dataArray objectAtIndex:[pickerView selectedRowInComponent:0]],[minArray objectAtIndex:[pickerView selectedRowInComponent:1]]);
NSString *hour = [dataArray objectAtIndex:[pickerView selectedRowInComponent:0]];
NSLog(@"%@", hour);
NSString *minute = [minArray objectAtIndex:[pickerView selectedRowInComponent:1]];
NSLog(@"%@", minute);
NSString *totalTime = [totalTime stringByAppendingFormat:@"%@%@", hour, minute];
NSLog(@"%@", totalTime);
//[self.tableView reloadData];
}
答案 0 :(得分:2)
您的totalTime
声明在其自己的初始值设定项中使用。改变这一行:
NSString *totalTime = [totalTime stringByAppendingFormat:@"%@%@", hour, minute];
到这一行:
NSString *totalTime = [NSString stringWithFormat:@"%@%@", hour, minute];
答案 1 :(得分:1)
NSString *totalTime = [hour stringByAppendingString:minute];
将是一个简单的解决方案。