MaikelS
MaikelS

Reputation: 1299

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 selectedRowInComponent:1]];
NSLog(@"%@", minute);

NSString *totalTime = [totalTime stringByAppendingFormat:@"%@%@", hour, minute];
NSLog(@"%@", totalTime);
//[self.tableView reloadData];
}

Upvotes: 0

Views: 166

Answers (2)

Nitish
Nitish

Reputation: 14113

NSString *totalTime = [hour stringByAppendingString:minute];  

will be a simple solution.

Upvotes: 1

Eimantas
Eimantas

Reputation: 49344

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];

Upvotes: 2

Related Questions