A bug about UIPickerView, uipickerviewbug

Source: Internet
Author: User

A bug about UIPickerView, uipickerviewbug

First, let me describe the occurrence of a bug:


When using UIPickerView to select a city, the following figure shows a Bug1, on iOS 6, and 2. Select "Hong Kong" or "Macao" in the province column of Picker's data. 3. Then slide the PickerView second-level options, the result is a crash, and no Delegate4 is skipped. This problem does not exist on iOS 7 or a later mobile phone.

The bug message is as follows:

19:46:00. 711 then he [1719: 907] *** Assertion failure in-[UITableViewRowData rectForRow: inSection:],/SourceCache/UIKit/UIKit-2380.17/UITableViewRowData. m: 1630

19:46:00. 915 he [1719: 907] *** Terminating app due to uncaught exception 'nsinternalinconsistencyexception', reason: 'request for rect at invalid index path (<NSIndexPath 0x1fb81370> 2 indexes [0, 0])'

*** First throw call stack:

(Commandid 00000000000000000x35f04919 0x3606ec63 0x35fd923b 0x35ff26ed 0x35fd3d89 000000000000000000000000000000000x35ec91e7 000000000x37ba85a3 00000x34083173 00000000000000000x34083117)

Libc ++ abi. dylib: terminate called throwing an exception


After searching for a long time, I saw a solution from online users, but I tried it and it seems that something is missing. So I uploaded all the code of the solution, hope to help friends who encounter the same problem.


Solution:


-(NSInteger) pickerView :( UIPickerView *) pickerView numberOfRowsInComponent :( NSInteger) component {// if the corresponding array in the current component is empty, it is determined that if it is null, returns 1 if ([[self. pickerArray objectAtIndex: component] count] <= 0) {return 1;} return [[self. pickerArray objectAtIndex: component] count];}-(UIView *) pickerView :( UIPickerView *) pickerView viewForRow :( NSInteger) row forComponent :( NSInteger) component reusingView :( UIView *) View {UILabel * label = (UILabel *) view; if (! Label) {label = [[[UILabel alloc] initWithFrame: CGRectMake (0, 0,320, 20)] autorelease]; label. backgroundColor = [UIColor clearColor]; label. textAlignment = UITextAlignmentCenter; label. adjustsFontSizeToFitWidth = YES; label. numberOfLines = 2; label. minimumFontSize = 8.0f;} label. text = [[self. pickerArray objectAtIndex: component] count]? [[Self. pickerArray objectAtIndex: component] objectAtIndex: row] objectForKey: @ "hintValue"]: @ ""; // if ([self. pickerArray objectAtIndex: component] count] <= 0) {label. userInteractionEnabled = NO;} else {label. userInteractionEnabled = YES;} return label ;}



Click UIButton to bring up a UIPickerView. How can this problem be solved ??

Create a member variable
And a BOOL object to determine whether to hide the PickerView {
UIPickerView * PickerView;
BOOL show;
}
-(Void) viewDidLoad

{

[Super viewDidLoad];

Manually load a UIPickerView:

PickerView = [[UIPickerView alloc] init];

UIDatePicker * DateP = [[UIDatePicker alloc] init];

DateP. datePickerMode = UIDatePickerModeCountDownTimer;

[DateP setDate: [NSDate date];

[PickerView addSubview: DateP];
// Initialize the PickerView to be hidden and give show a BOOL value to it. YES
Show = YES;

PickerView. hidden = YES;

[Self. view addSubview: PickerView];

}
Give UIButton a click event and then change the show BOOL value:
-(Void) click {
If (show = YES ){
PickerView. hidden = NO;
Show = NO;
} Else {
PickerView. hidden = YES;
Show = NO;
}
}
Click "hide" and click "show ..
 
This seems to be a BUG.

Bug
The Origin of "BUG:
The original intention of Bug is "Bug" or "Bug ". But now, in computer systems or programs, if some undiscovered defects or problems are hidden, people call them "Bugs", what is the problem?
Originally, the first generation of computers was composed of many large and expensive vacuum tubes, and used a lot of electricity to make vacuum tubes shine. Maybe it is the light and heat produced by computer operation that leads to a small bug? Bug? Drilling into a vacuum tube makes the entire computer unable to work. After spending half a day, the researchers finally found the cause. After the bug was removed from the vacuum tube, the computer went back to normal. Later, the term Bug was used to indicate hidden errors, defects, or problems in computer systems or programs.
In contrast to a Bug, people call the process of discovering and correcting a Bug "Debug", that is, "catch a Bug" or "insecticide ". Unfortunately, there is still no correct word for "Bug" in Chinese, so the word "Bug" can only be referenced directly. Although the word "Bug" is also used to replace "Bug", it is prone to ambiguity and thus cannot be promoted.
The so-called "(Bug)" refers to the hardware, system software (such as the operating system) or application software (such as text processing software) errors of the computer system. There are two causes for hardware errors: one is design errors and the other is aging and failure of hardware components. All software errors are factory design errors. The prompt that the user has performed illegal operations is not the responsibility of the software vendor. The user may perform incorrect operations, such as adding but pressing the subtraction key. In this way, the user will get an incorrect result, but it will not cause a bug. A basic requirement of software vendors when designing products is that users are not allowed to perform illegal operations. All operations permitted by users are legal. The user has no way to know what the manufacturer thinks and what operation sequence is illegal.
Since the birth of the computer, there has been a computer BUG. The first documented bug was discovered by GraceHopper, inventor of the compiler, a programmer from the US Navy. He became a general of the US Navy and led the development of the famous computer language Cobol.
September 9, 1945 three o'clock P.M. Lieutenant Harper is leading her group to construct a computer called the "Mark 2. This is not a complete electronic computer, it uses a large number of relays, an electronic mechanical device. The second world war is not over yet. Harper's team is working day and night. The IDC is an old building built during the First World War. It was a hot summer with no air conditioning in the room and all the windows were open for heat dissipation.
Suddenly, Mark 2 crashed. The technicians tried a lot of methods and finally found that the No. 70th relay had an error. Harper observed the faulty relay and found a moth lying in the middle, which had been killed by the relay. She was careful to clip the moth out with a video clip and paste it in the "Event Log Book" with transparent glue, and noted "the first instance for discovering bugs ." [1]
Since then, people have called computer errors a bug, and the work of searching for errors is called a debug ).
Hidden functional defects or errors in the program. Because the complexity of the software is beyond the control of ordinary people, mature operating systems such as Win95 and Win98 will occasionally release bugs. How to reduce or even eliminate bugs in the program has always been a topic of great importance to programmers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.