【代碼筆記】書架頁面

来源:http://www.cnblogs.com/yang-guang-girl/archive/2016/05/31/5544735.html
-Advertisement-
Play Games

一,效果圖。 二,工程圖。 三,代碼。 RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController : UIViewController <UITableViewDataSource,UITableViewDe ...


一,效果圖。

二,工程圖。

三,代碼。

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 self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //初始化背景圖
    [self initBackGroundView];
   
}
#pragma -mark -functions
-(void)initBackGroundView
{
    self.title=@"書架頁面";
    
    dataArray=[[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9", nil];
    
    myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 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(@"--點擊圖片的時候,所在的坐標-(%ld,%ld)--",path.row,btn.tag);
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that 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:CGRectMake(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;
}
複製代碼

 

 

   
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Fragment 裡面 使用輕量級的數據存儲sharepreference ,代碼思路清晰。保存輸入框裡面的數據,實現按鈕保存。 個人項目中簡單清晰代碼: 趙存檔 編寫 ,可以參考: 類繼承Fragment實現點擊事件: 本代碼來源個人博客:http://www.cnblogs.com/xiaobo ...
  • 現在開始寫博客,分享android開發中的心得。 ...
  • 運行結果列印: 原文文檔介紹: Runs the loop once, blocking for input in the specified mode until a given date. //執行loop一次,堵塞等待給定模式的輸入直至給定的時間點 Parameters mode The mo ...
  • 做基於WebView應用時,頁面上有一個輸入框,當輸入的文字過多時,超過輸入框的行數時,輸入框能夠滾動,這時間問題來了,輸入的提示箭頭會移動到輸入框外,如何解決這個問題呢,查找chromium源碼如下: void LoadIfNecessary(jobject context) { if (load ...
  • 1.代碼如下 (註釋都有) - (void)viewDidLoad { [super viewDidLoad]; UIImageView * bigImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100) ...
  • 複製並修改原有項目 複製之前創建的項目CC+CV操作 需要改動的地方: * 項目名字 * 應用包名 * R文件重新導包 接著修改件/AndroidManifest.xml中的包名:package="com.wuyudong.rwinrom" 簡單起見直接改為package="com.wuyudong ...
  • ~/Library/MobileDevice/Provisioning Profiles ...
  • 蘋果的通訊錄功能在iOS7,iOS8,iOS9 都有著一定的不同,iOS7和8用的是 <AddressBookUI/AddressBookUI.h> ,但是兩個系統版本的代理方法有一些變化,有些代理方法都標註了 NS_DEPRECATED_IOS(2_0, 8_0) 並推薦了另一個代理方法與之對應。 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...