AppDelegate.swift:

平鄉(xiāng)ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書(shū)銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書(shū)合作)期待與您的合作!
Customcell.swift:(自定義的cell)
//屏幕的寬
let kScreenWidth = UIScreen.main.bounds.size.width
//屏幕的高
let kScreenHeigh = UIScreen.main.bounds.size.height
RootTableViewController.swift:
UITableViewCell類能夠顯示出各種各樣的風(fēng)格,但有時(shí)候我們需要適應(yīng)不同的顯示模式下的顯示。今天的文章中,我們將使用table view去顯示一系列自定義的cell。
啟動(dòng)Xcode,選擇"Create a new Xcode project",然后選擇空應(yīng)用程序模板,點(diǎn)擊Next。命名為 CustomCells,然后照下圖那樣設(shè)置。
點(diǎn)擊Next,選擇項(xiàng)目的存放路徑,最后點(diǎn)擊Create。
這里需要添加兩個(gè)文件,UITableViewController以及custom cell對(duì)應(yīng)的xib文件。
Choose File | New File ,然后添加一個(gè)名為 TableViewController 的UITableViewController。
如圖:
對(duì)于這個(gè)controller,我們并不需要xib文件,所以直接點(diǎn)擊Next創(chuàng)建。
重新創(chuàng)建文件,這次我們是創(chuàng)建一個(gè)空的 xib 文件,如下圖:
點(diǎn)擊Next,確保Device Family被設(shè)置為iPad,再點(diǎn)擊Next,在默認(rèn)路徑下保存為 CellNib 文件。
接著打開(kāi) CellNib.xib 文件。在上面拖放幾個(gè) label:
這里第一個(gè)Label的字體大小是27,字體是System Italic。而其他的Label全部都是默認(rèn)設(shè)置。
下一步就是為文本依然是"Label"的Label設(shè)置tag。
將第一個(gè)大字體的Label設(shè)置tag=1,然后設(shè)置Address1,Address2,Phone,Cell右邊的Label的tag分別為2,3,4,5。
接著需要修改xib的File's Owner的所屬類。這里選擇為 TableViewController。
打開(kāi) TableViewController.h 然后添加這些屬性:
#import uikit uikit.h=""span class="referer"@interface/span TableViewController : UITableViewController
@property (nonatomic, strong) NSArray *cellContent;
@property (nonatomic, strong) IBOutlet UITableViewCell *customCell;span class="referer"@end/span /uikit
這個(gè)演示中,我們定義一個(gè)數(shù)組來(lái)記錄所有cell的內(nèi)容,還需要如下圖那樣,設(shè)置設(shè)置好 customCell的outlet。
現(xiàn)在打開(kāi)TableViewController.m做出如下更改:
#import "TableViewController.h"span class="referer"@interface/span TableViewController ()span class="referer"@end/span
@implementation TableViewController
@synthesize cellContent, customCell;
- (NSArray *)cellContent
{
cellContent = [[NSArray alloc] initWithObjects:
[NSArray arrayWithObjects:@"Alex Ander",
@"213 4th St.", @"Apt. 17", @"555-555-5555", @"111-111-1111", nil],
[NSArray arrayWithObjects:@"Jane Doe",
@"4 Any Ave.", @"Suite 2", @"123-456-7890", @"098-765-4321", nil],
[NSArray arrayWithObjects:@"Bill Smith",
@"63 Smith Dr.", @"", @"678-765-1236", @"987-234-4987", nil],
[NSArray arrayWithObjects:@"Mike Taylor",
@"3145 Happy Ct.", @"", @"654-321-9871", @"654-385-1594", nil
這里我默認(rèn)你是要自定義UITableViewCell.首先 你創(chuàng)建一個(gè)類繼承UITableViewCell。然后在tableview的delegate中的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 實(shí)現(xiàn)中 return你自定義的cell就ok了
1、先把Cell的頭文件import進(jìn)來(lái)
2、[tableview_main registerNib:[UINib nibWithNibName:@"UserCallDealTableViewCell" bundle:nil] forCellReuseIdentifier:@"UserCallDealTableViewCellMark"];
使用這個(gè)方法注冊(cè)自定義Cell tableview_main就是當(dāng)前tableview實(shí)力化對(duì)象,然后UserCallDealTableViewCell這個(gè)字符串就是xib的名稱,UserCallDealTableViewCellMark是重用機(jī)制的標(biāo)記,配合等一下的代理方法使用
3、最后在代理方法控制自定義cell
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *identification = @"UserCallDealTableViewCellMark";
UserCallDealTableViewCell *cell = [tableview_main dequeueReusableCellWithIdentifier:identification];
if (cell != nil) {
NSDictionary *dict_tmp = arry_dataSource[indexPath.row];
cell-label_doctor_name.text = dict_tmp[@"doctorName"];
cell-label_hosptial.text = dict_tmp[@"hospitalName"];
if ([dict_tmp[@"sstatus"] isEqualToString:@"S"]) {
cell-label_status.text = @"預(yù)約成功";
}
else{
cell-label_status.text = @"預(yù)約失敗";
}
NSString *string_date = @{@"0":@"上午",@"1":@"下午"}[dict_tmp[@"timeq"]];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-dd"];
NSDate *date_tmp = [formatter dateFromString:dict_tmp[@"date"]];
[formatter setDateFormat:[NSString stringWithFormat:@"MM月dd日 EEEE %@ mm:HH",string_date]];
cell-label_info.text = [formatter stringFromDate:date_tmp];
return cell;
}
return [UITableViewCell new];//這個(gè)地方我建議不要返回nil因?yàn)榭赡軙?huì)導(dǎo)致崩潰
}
開(kāi)發(fā)中經(jīng)常在cell上添加scrollView展示多張圖片,但是這是scrollView的點(diǎn)擊事件會(huì)與cell的點(diǎn)擊事件沖突,這里介紹一個(gè)簡(jiǎn)單的方法,使scrollView既可以滑動(dòng),cell的點(diǎn)擊事件也好用。
在自定義cell中,添加下面兩句話:
? ? self.scrollView.userInteractionEnabled = NO;//關(guān)閉scrollView的用戶交互
? [self.contentView addGestureRecognizer:self.scrollView.panGestureRecognizer];//讓cell捕捉scrollView的點(diǎn)擊事件并相應(yīng)
除此之外,也可以給UIImageView添加手勢(shì),但是比較麻煩,不如這兩句話方便。
但是此時(shí)需加上這一句;
self.myImageView.userInteractionEnabled = YES;//用戶交互,默認(rèn)關(guān)閉,BOOL類型
UITapGestureRecognizer *tap =[[ UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
tap.numberOfTouchesRequired = 1;
[self.myImageView addGestureRecognizer:tap];
-(void)tapAction:(UITapGestureRecognizer *)sender{
//實(shí)現(xiàn)方法
}
本文名稱:ios開(kāi)發(fā)自定義cell,ios開(kāi)發(fā)自定義導(dǎo)航欄
標(biāo)題來(lái)源:http://chinadenli.net/article22/dsedhcc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈、外貿(mào)建站、域名注冊(cè)、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)