Pickerview crash
I want to get 2 values from a UIPickerView and merge them in one string. I can fetch them correctly, but the merging in the last NSString keeps crashing with sigabrt when I try to NSLog it.
- (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 selec开发者_高级运维tedRowInComponent:1]];
NSLog(@"%@", minute);
NSString *totalTime = [totalTime stringByAppendingFormat:@"%@%@", hour, minute];
NSLog(@"%@", totalTime);
//[self.tableView reloadData];
}
Your totalTime
in declaration is used in its own initializer. Change this line:
NSString *totalTime = [totalTime stringByAppendingFormat:@"%@%@", hour, minute];
to this line:
NSString *totalTime = [NSString stringWithFormat:@"%@%@", hour, minute];
NSString *totalTime = [hour stringByAppendingString:minute];
will be a simple solution.
精彩评论