Objective-C has a brain problem.
Description:
The asiformrequest class is a subclass of the asihttprequest class. In the function, retain is performed on the asiformrequest pointer returned in another place. Out of this function, the retain pointer can be accessed, but all attributes and methods inherited from the parent class are out of scope, use itProgramCrash.
The solution is simple. When retain is used, do not use the retain subclass pointer. The retain parent class pointer can be used.
- (Asihttprequest * ) _ Getsinarequest {
Asihttprequest * Request = [Sinaapi uploadwithimage: selectedphoto status: Text. Text];
Request. Delegate = Self;
Request. showaccurateprogress = Yes;
Request. uploadprogressdelegate = Sinapostprogress;
[Request retain];
Return Request;
}
- ( Void ) Uploadphoto
{
If ([Sinaapi isauthorized]) {
Sinaposted = No;
Sinapostrequest = [Self _ getsinarequest];
[Sinapostrequest startasynchronous];
}
Else {
Sinaposted = Yes;
}
// ......
}
-(Void) Cancel: (ID) sender {
If (Sinapostrequest ){
If ( ! [Sinapostrequest isfinished]) { // If the retain is an asiformrequest pointer, it will immediately die.
[Sinapostrequest cleardelegatesandcancel];
}
[Sinapostrequest release];
}
Sinapostrequest = Nil;
[Progresswindow hideimmediately];
}