When passing parameters between view controllers, pay special attention to the "wild Pointer" issue.
Because the program is always beating between view controllers, some view controllers have variables (related to the UI). When the view jumps, will be released (to save iPhone memory ?).
For example:
In a viewcontroller:
Recipientroll * controller = [[recipientroll alloc] initwithnibname: @ "recipientroll" msgtext: tvbill. Text
Expenseid: expense_id];
[Self presentmodalviewcontroller: controller animated: Yes];
Pay attention to the red part and pass a string parameter to another viewcontroller. However, this parameter references the UI control attributes of this viewcontroller.
Then, another viewcontroller is displayed in the form of a pattern. The ui of the first viewcontroller is released. So the memory of the string you passed is released, and its lifecycle is only a short period of time during the construction. When the mode form is displayed, it is released. If you want to do something with it later and the program crashes, xcode reports exec bad.
Therefore, we need to use its short life cycle time to copy strings. Write in the constructor as follows:
-(ID) initwithnibname :( nsstring *) nibnameornil msgtext :( nsstring *) d expenseid :( INT) idx {
// Nslog (@ "initwithnibname ");
If (Self = [Super initwithnibname: nibnameornil Bundle: Nil]) {
Expense_id = idx;
Msgtext = [[nsstring alloc] initwithstring: d];
// Do not write it like this: msgtext = d
}
Return self;
}
In this way, you can safely use the msgtext variable before the viewcontroller is released.