Objective-C out of scope

Source: Internet
Author: User

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

}

 

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.