How to add the iPhone three20 to the project, and how to add and delete the image button.

Source: Internet
Author: User

Recently, due to project requirements, you need to create an album viewer to view the project images. As a result, three20 is very powerful and has its own album function, so it is referenced in the project.

First, download three20 and install it in the project.

If you want to manually add three20 to xcode4.2, refer to this link: Add three20 to xcode4.2 tutorial

If you want to add three20 to xcode through the command, you can refer to this link to add three20 to xcode tutorial through the command

It is faster to add three20 to xcdoe using commands.

However, pay attention to the following points.

1. Try to keep the downloaded three20 in the same directory as the project, which will be more convenient in subsequent settings.

2. If the project name is different from that of targets, execute the following command when executing the command.

3. Follow these steps to add the album to your project and add the image album to the project.

3. HowProgramClick a button and navigate to the three20 album.CodeFor more information about navigation, see this link. Navigation tutorial

-(Ibaction) viewphoto :( ID) sender

{
Nslog ( @" % @ " , Currentimagename );
Nslog ( @" % D " , [Currentimagename retaincount]);
[[Tturlrequestqueue mainqueue] setmaxcontentlength: 0 ];
Ttnavigator * navigator = [ttnavigator navigator];
Navigator. Window = [uiapplication sharedapplication]. keywindow;
Tturlmap * map = navigator. urlmap;
[Map From : @" TT: // appphotos " Tosharedviewcontroller: [photoviewcontroller Class ];
[Navigator openurlaction: [tturlaction actionwithurlpath: @" TT: // appphotos " ];

4. To return data from the album to the original project, add the following code in photoviewcontroller. h:

4.1 Add the return button to the navigation bar

-(Void) Viewdidload {

Uibarbuttonitem * listviewbackbtn = [[uibarbuttonitem alloc] initwithtitle: @" Test "
Style: uibarbuttonitemstyleplain
Target: Self
Action: @ selector (Goback :)];
Self. navigationitem. leftbarbuttonitem = listviewbackbtn;
Self. navigationitem. hidesbackbutton = yes;
[Listviewbackbtn release];
Self. photosource = [photoset samplephotoset];
Self. centerphotoindex = currentcaptureindex;

4.2 Add return button event

//Back to the video watching page

-( Void ) Goback :( ID) sender {

[[Ttnavigator navigator] removeallviewcontrollers];
}

5. How to add deletion events to an album.

5.1 for details about the add and delete buttons and events, refer to this tutorial to add and delete events. 2

5.2 Delete the image ZTE event. As follows:

//Delete Image

-( Void ) Deletephotoatindex :( nsinteger) Index
{
Nsmutablearray * muphotos = [photoset samplephotoset]. photos;
Photo * removephoto = [muphotos objectatindex: Index];
Nsstring * removephotoname = removephoto. Caption;
[Self removephotosofgateents: Index removephotoname: removephotoname];
// [Muphotos removeobjectatindex: Index];
Self. photosource = [photoset samplephotoset];
Self. centerphotoindex = index;

}

-( Void ) Removephotosofpolicents :( nsinteger) index removephotoname :( nsstring *) removephotoname
{
Nsfilemanager * filemanage = [nsfilemanager defaultmanager];
Nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes );
Nsstring * documentdirectory = [paths objectatindex: 0 ];
Nsstring * bigimagepath = [documentdirectory stringbyappendingpathcomponent: [nsstring stringwithformat: @" Bigimage/% @ " , Removephotoname];
Nsstring * smallimagepath = [documentdirectory stringbyappendingpathcomponent: [nsstring stringwithformat: @" Smallimage/small _ % @ " , Removephotoname];
Nserror * error = nil;
[Filemanage removeitematpath: bigimagepath error: & error];
[Filemanage removeitematpath: smallimagepath error: & error];

5.3 If you upload an image and return to the thumbnail viewer, you will find that the deleted image is still in the thumbnail viewer. In this case, you need to modify the ttphotoviewcontroller class: the red part is newly added. In this way, the album thumbnails can be synchronized.

Ttphotoviewcontroller

-( Void ) Showthumbnails {
Nsstring * url = [self urlforthumbnails];
If (! _ Thumbscontroller ){
If (URL ){
// The photo source has a URL Mapping in tturlmap, so we use that to show the thumbs
Nsdictionary * query = [nsdictionary dictionarywithobject: Self forkey: @" Delegate " ];
Ttbasenavigator * navigator = [ttbasenavigator navigatorforview: Self. View];
_ Thumbscontroller = [[navigator viewcontrollerforurl: URL query: Query] retain];
[Navigator. urlmap setobject: _ thumbscontroller forurl: url];

}Else{
//The photo source had no URL Mapping in tturlmap, so we let the subclass show the thumbs
_ Thumbscontroller = [[self createthumbsviewcontroller] retain];
_ Thumbscontroller. photosource = _ photosource;
}
}

If(URL ){
Ttopenurlfromview (URL, self. View );

}< span style = "color: # 0000ff;"> else {< br> If ([self. navigationcontroller iskindofclass: [ttnavigationcontroller class ]) {
_ thumbscontroller. photosource = _ photosource;
[(ttnavigationcontroller *) self. navigationcontroller
pushviewcontroller: _ thumbscontroller
animatedwithtransition: uiviewanimationtransitioncurldown];

}Else{
_ Thumbscontroller. photosource = _ photosource;
[Self. navigationcontroller pushviewcontroller: _ thumbscontroller animated: Yes];
}
}
}

 

 

 

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.