开发者

Pickerview crash

开发者 https://www.devze.com 2023-04-12 03:31 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消