"Code Notes" Bookshelf page

Source: Internet
Author: User

One.

Two, engineering drawings.

Three, code.

RootViewController.h

#import <UIKit/UIKit.h> @interface Rootviewcontroller:uiviewcontroller<uitableviewdatasource, uitableviewdelegate>{    Nsmutablearray * dataarray;    UITableView * Mytableview;} @end

Rootviewcontroller.m

#import "RootViewController.h"//cell#import "RootTableViewCell.h" @interface Rootviewcontroller () @ End@implementation rootviewcontroller-(ID) initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *)    nibbundleornil{self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;}    -(void) viewdidload{[Super Viewdidload];        Do any additional setup after loading the view.   Initialize the background map [self initbackgroundview];        } #pragma-mark-functions-(void) initbackgroundview{[email protected] "Bookshelf page";        Dataarray=[[nsmutablearray alloc]initwithobjects:@ "1", @ "2", @ "3", @ "4", @ "5", @ "6", @ "7", @ "8", @ "9", nil];    Mytableview = [[UITableView alloc]initwithframe:cgrectmake (0, 0, +, 416) Style:uitableviewstyleplain];    Mytableview.delegate = self;    Mytableview.datasource = self; [Self.view Addsubview:mytableview];} #pragma-mark-uitableviewdelegate-(Nsinteger) TableView: (UITableView *) TableView NumberoFrowsinsection: (Nsinteger) section{return 3;}    -(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return 376/3;    }-(uitableviewcell*) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{    Roottableviewcell * cell = [TableView dequeuereusablecellwithidentifier:@ "ID"]; if (cell = = nil) {cell =[[roottableviewcell alloc]initwithstyle:uitableviewcellstylevalue1 reuseidentifier:@ "ID"    ];        } Cell.tag = Indexpath.row;    [Cell.bookleft addtarget:self Action: @selector (ButtonClick:) forcontrolevents:uicontroleventtouchupinside];    [Cell.bookmiddle addtarget:self Action: @selector (ButtonClick:) forcontrolevents:uicontroleventtouchupinside];        [Cell.bookright addtarget:self Action: @selector (ButtonClick:) forcontrolevents:uicontroleventtouchupinside]; [Cell.bookleft setbackgroundimage:[uiimage imagenamed:[nsstring stringwithformat:@ "%@.jpg", [DataArray OBJECTATINDEX:INDEXPATH.ROW*3]] forState:uicontrolstatenormal]; [Cell.bookmiddle setbackgroundimage:[uiimage imagenamed:[nsstring stringwithformat:@ "%@.jpg", [DataArray    OBJECTATINDEX:INDEXPATH.ROW*3+1]] [forstate:uicontrolstatenormal]; [Cell.bookright setbackgroundimage:[uiimage imagenamed:[nsstring stringwithformat:@ "%@.jpg", [DataArray    OBJECTATINDEX:INDEXPATH.ROW*3+2]] [forstate:uicontrolstatenormal];    NSLog (@ "--celll.tag--%ld", Cell.tag);    return cell;  } #pragma-mark-doclickactions-(void) ButtonClick: (uibutton*) btn{Roottableviewcell * cell = (Roottableviewcell *) [[BTN    Superview] Superview];    Nsindexpath * Path = [Mytableview Indexpathforcell:cell]; NSLog (@ "--When you click on the image, the coordinates-(%LD,%LD)--", Path.row,btn.tag);}    -(void) didreceivememorywarning{[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end

RootTableViewCell.h

#import <UIKit/UIKit.h> @interface roottableviewcell:uitableviewcell@property (nonatomic,strong) UIButton * Bookleft, @property (nonatomic,strong) UIButton * bookmiddle; @property (nonatomic,strong) UIButton * bookright; @end

roottableviewcell.m

#import "RootTableViewCell.h" @implementation roottableviewcell@synthesize bookleft @synthesize bookmiddle;@    Synthesize bookright;-(ID) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) reuseIdentifier{    self = [super Initwithstyle:style reuseidentifier:reuseidentifier]; if (self) {///initialization code Uiimageview * imageview= [[Uiimageview Alloc]initwithframe:cgrec        Tmake (0, 0, 320, 416/3)];        Imageview.image = [UIImage imagenamed:@ "Bookshelfcell.png"];                [Self addsubview:imageview];        Bookleft = [UIButton buttonwithtype:uibuttontypecustom];        Bookleft.frame = CGRectMake (10, 10, 280/3, 376/3-20);                Bookleft.tag = 1;        Bookmiddle = [UIButton buttonwithtype:uibuttontypecustom];        Bookmiddle.frame = CGRectMake (20+280/3, 10, 280/3, 376/3-20);                Bookmiddle.tag = 2;        Bookright = [UIButton buttonwithtype:uibuttontypecustom]; Bookright.frame = CGRectMake (30+280/3*2, 10,280/3, 376/3-20);                Bookright.tag = 3;        [Self addsubview:bookleft];        [Self addsubview:bookmiddle];    [Self addsubview:bookright]; } return self;}

  

"Code Notes" Bookshelf page

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.